Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
27.8k views
in Java FTP by (160 points)
Hello,

I am using edtFTPj/Free version 2.0.2

I am getting this error -

java.net.SocketException: Connection reset by peer: socket write error

when doing this -

FileTransferClient ftp = new FileTransferClient();
ftp.setRemoteHost(host);
ftp.setUserName(user);
ftp.setPassword(password);
ftp.connect();
ftp.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.PASV);
ftp.setContentType(FTPTransferType.BINARY);
ftp.changeDirectory(directory);
while ( st.hasMoreTokens() )
{
ftp.uploadFile(resultDir + localFile, remoteFile);
}
ftp.disconnect();

The error does not happen every time, maybe 10% of the time.

Any help would be appreciated.

This is the debug info -

DEBUG [FTPClient] 21 May 2008 13:14:00.975 : Class: com.enterprisedt.net.ftp.FTPClient
Version: 2.0.2
Build timestamp: 31-Mar-2008 14:30:20 EST
Java version: 1.5.0_06
CLASSPATH: .\;..\;C:\Program .\;..\;C:\Program Files\Java\jre1.5.0_06\lib;D:\Webprojects\DEV\CDCINFO\scripts\DX\newDXI\mail.jar;D:\Webprojects\DEV\CDCINFO\scripts\DX\newDXI\activation.jar;D:\Webprojects\DEV\CDCINFO\scripts\DX\newDXI\jtds-0.9.jar;D:\Webprojects\DEV\CDCINFO\scripts\DX\newDXI\edtftpj-2.0.2.jar;
OS name: Windows 2003
OS arch: x86
OS version: 5.2

DEBUG [FileTransferClient] 21 May 2008 13:14:00.975 : Configured client
DEBUG [FTPClient] 21 May 2008 13:14:00.975 : Connecting to /10.24.253.11:21
DEBUG [SocketUtils] 21 May 2008 13:14:00.975 : Invoking connect with timeout=60000
DEBUG [SocketUtils] 21 May 2008 13:14:01.68 : Connected successfully
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.162 : 220 Microsoft FTP Service
DEBUG [FileTransferClient] 21 May 2008 13:14:01.162 : Client connected
DEBUG [FileTransferClient] 21 May 2008 13:14:01.162 : Logging in
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.162 : ---> USER FTPUser
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.256 : 331 Password required for FTPUser.
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.256 : ---> PASS ********
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.350 : 230 User FTPUser logged in.
DEBUG [FileTransferClient] 21 May 2008 13:14:01.350 : Logged in
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.350 : ---> TYPE I
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.443 : 200 Type set to I.
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.443 : ---> TYPE I
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.537 : 200 Type set to I.
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.537 : ---> CWD content\dev
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.631 : 250 CWD command successful.
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.631 : ---> PASV
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.725 : 227 Entering Passive Mode (10,24,253,11,9,174).
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.725 : Substituting server supplied IP (10.24.253.11) with remote host IP (10.24.253.11)
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.818 : ---> STOR siebel-delete-out.xml
DEBUG [FTPControlSocket] 21 May 2008 13:14:01.912 : 125 Data connection already open; Transfer starting.
DEBUG [FTPClient] 21 May 2008 13:14:03.287 : Transferred 133956 bytes to remote host
DEBUG [FTPControlSocket] 21 May 2008 13:14:03.381 : 226 Transfer complete.
DEBUG [FTPControlSocket] 21 May 2008 13:14:03.381 : ---> PASV
DEBUG [FTPControlSocket] 21 May 2008 13:14:03.475 : 227 Entering Passive Mode (10,24,253,11,9,175).
DEBUG [FTPControlSocket] 21 May 2008 13:14:03.475 : Substituting server supplied IP (10.24.253.11) with remote host IP (10.24.253.11)
DEBUG [FTPControlSocket] 21 May 2008 13:14:03.568 : ---> STOR siebel-delete-out.txt
DEBUG [FTPControlSocket] 21 May 2008 13:14:03.662 : 125 Data connection already open; Transfer starting.
DEBUG [FTPClient] 21 May 2008 13:14:03.678 : Transferred 22325 bytes to remote host
DEBUG [FTPControlSocket] 21 May 2008 13:14:04.756 : 226 Transfer complete.
DEBUG [FTPControlSocket] 21 May 2008 13:14:04.756 : ---> PASV
DEBUG [FTPControlSocket] 21 May 2008 13:14:04.912 : 227 Entering Passive Mode (10,24,253,11,9,176).
DEBUG [FTPControlSocket] 21 May 2008 13:14:04.912 : Substituting server supplied IP (10.24.253.11) with remote host IP (10.24.253.11)
DEBUG [FTPControlSocket] 21 May 2008 13:14:05.6 : ---> STOR siebel-content-out.xml
DEBUG [FTPControlSocket] 21 May 2008 13:14:05.100 : 125 Data connection already open; Transfer starting.
ERROR [FTPClient] 21 May 2008 13:14:18.177 : Caught and rethrowing exception in getDataAfterInitGet() : Connection reset by peer: socket write error
java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.DataOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.write(Unknown Source)
at com.enterprisedt.net.ftp.FTPClient.putData(FTPClient.java:2380)
at com.enterprisedt.net.ftp.FTPClient.put(FTPClient.java:2065)
at com.enterprisedt.net.ftp.FTPClient.put(FTPClient.java:2047)
at com.enterprisedt.net.ftp.FileTransferClient.uploadFile(FileTransferClient.java:639)
at com.enterprisedt.net.ftp.FileTransferClient.uploadFile(FileTransferClient.java:613)
at NewDXI.FTPResultsToPoroduction(NewDXI.java:5622)
at NewDXI.findAndRunProcStep(NewDXI.java:3605)
at NewDXI.runProcesses(NewDXI.java:644)
at NewDXI.initializeAndRun(NewDXI.java:273)
at NewDXI.main(NewDXI.java:161)

6 Answers

0 votes
by (161k points)
Looks like the server is terminating your connection. It could be that you are transferring a lot of small files in succession. You might need to space them out a bit.
0 votes
by (140 points)
Looks like the server is terminating your connection. It could be that you are transferring a lot of small files in succession. You might need to space them out a bit.


I have the same problem also. Large file transfer is fine.
What you mean by "..need to space them out a bit.."?
Can you clarify what should be done on that?
0 votes
by (161k points)
Each FTP transfer consumes a socket, and there's only a finite number available to a process. TCP/IP doesn't immediately return closed sockets to the available pool - it takes a couple of minutes (google TIME_WAIT for more details).

So many small rapid transfers can exhaust the number of sockets. With FTP, sometimes you have to slow down the transfers by sleeping (say) every 25 files for (say) 30 seconds. You can also increase the number of sockets available - easy on Unix with ulimit.
0 votes
by (160 points)
After upgrading to ColdFusion 8 and not changing any of the ftp code, the "connection reset by peer" error stopped happening.
0 votes
by (161k points)
Interesting. There could have been a resource leak in the previous version I suppose, or some kind of bug.
0 votes
by (140 points)
I know this problem happened a long time ago, but I wanted to post my solution. I had the same problem because I was requesting many small files from the FTP server. The problem was that for each file I opened and closed my connection which was what wore all the ports out. So to solve my problem I opened my connection before I entered into a loop and then looped through my query, retrieving a file for each record in the query and saving it to my server, then closed the connection after the loop. This way you only use one connection and you don't overtax the ports.

Categories

...