I am using 2 FileTransferClient.uploadFile() statements within a for loop to continously upload 2 kinds of files to an FTP server.
I get a SocketTimeoutException with a message "Read timed out" whenever it hits the second uploadFile() stmt within the for loop.
But when I introduce a sleep statement between the uploadFile() stmts, it works fine.
The code is as follows,
for(some condition)
{
//some stmts
...
docName = buff.toString() + Constants.OUT;
ftpClient.uploadFile(srcFolder + docName, docName);
logger.debug("Uploaded document to FTP server : " + docName);
//Starting from 500 millis, I reduced the interval and reached this min level.
//I tested for filesize range between 2 KB and 128MB.
//Filesize does not seem to have an impact on the interval, but with an
//interval of 5 millis a random file got the "Read timed out" error and not
//the 128 MB file (the max sized file).
Thread.sleep(10);
indName = buff.toString() + Constants.IND;
ftpClient.uploadFile(srcFolder + indName, indName);
logger.debug("Uploaded document metadata to FTP server : " + indName);
//some stmts
...
}
The stack trace is as follows,
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:408)
at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:450)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:182)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.readLine(BufferedReader.java:299)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at com.enterprisedt.net.ftp.FTPControlSocket.readReply(FTPControlSocket.java:847)
at com.enterprisedt.net.ftp.FTPControlSocket.sendCommand(FTPControlSocket.java:815)
at com.enterprisedt.net.ftp.FTPControlSocket.setDataPort(FTPControlSocket.java:649)
at com.enterprisedt.net.ftp.FTPControlSocket.sendPORTCommand(FTPControlSocket.java:527)
at com.enterprisedt.net.ftp.FTPControlSocket.createDataSocketActive(FTPControlSocket.java:508)
at com.enterprisedt.net.ftp.FTPControlSocket.createDataSocket(FTPControlSocket.java:479)
at com.enterprisedt.net.ftp.FTPClient.setupDataSocket(FTPClient.java:2160)
at com.enterprisedt.net.ftp.FTPClient.initPut(FTPClient.java:2195)
at com.enterprisedt.net.ftp.FTPClient.putData(FTPClient.java:2278)
at com.enterprisedt.net.ftp.FTPClient.put(FTPClient.java:2021)
at com.enterprisedt.net.ftp.FTPClient.put(FTPClient.java:2003)
at com.enterprisedt.net.ftp.FileTransferClient.uploadFile(FileTransferClient.java:593)
at com.enterprisedt.net.ftp.FileTransferClient.uploadFile(FileTransferClient.java:567)
at com.ssc.reti.transfer.TransferHandler.transfer(TransferHandler.java:257)
at com.ssc.reti.transfer.TransferHandler.main(TransferHandler.java:339)
I also enabled the EDT logger and got the following log stmts,
DEBUG [FTPClient] 4 Jan 2008 15:20:29.331 : Class: com.enterprisedt.net.ftp.FTPClient
Version: 2.0.0
Build timestamp: 20-Dec-2007 11:27:53 EST
Java version: 1.4.2_08
CLASSPATH: C:\VMFS\J2EE\RETI\bin;C:\VMFS\J2EE\RETI\lib\log4j.jar;
C:\Documentum\Shared\dfcbase.jar;C:\Documentum\Shared\dfc.jar;
C:\senthil\softwares\edtftpj-2.0.0\lib\edtftpj.jar
OS name: Windows XP
OS arch: x86
OS version: 5.1
DEBUG [FileTransferClient] 4 Jan 2008 15:20:29.347 : Configured client
DEBUG [FTPClient] 4 Jan 2008 15:20:29.347 : Connecting to /10.46.37.31:21
DEBUG [SocketUtils] 4 Jan 2008 15:20:29.362 : Invoking connect with timeout=60000
DEBUG [SocketUtils] 4 Jan 2008 15:20:29.362 : Connected successfully
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.362 : 220 Golden FTP Server ready v3.66
DEBUG [FileTransferClient] 4 Jan 2008 15:20:29.378 : Client connected
DEBUG [FileTransferClient] 4 Jan 2008 15:20:29.378 : Logging in
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.378 : ---> USER anonymous
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.378 : 331 User name okay, need password.
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.378 : ---> PASS ********
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.378 : 230 User logged in, proceed.
DEBUG [FileTransferClient] 4 Jan 2008 15:20:29.378 : Logged in
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.378 : ---> TYPE I
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.378 : 200 Type set to I.
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.378 : ---> TYPE I
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.378 : 200 Type set to I.
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.378 : ---> CWD FTP
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.393 : 250 CWD Command successful.
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.440 : ListenOnAllInterfaces=true
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.440 : ---> PORT 10,46,37,31,9,235
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.440 : 200 PORT Command successful.
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.440 : ---> STOR rxt.ibt.ppcm.b0001.d0000001.doc.out
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.440 : 150 File status okay; about to open data connection.
DEBUG [FTPActiveDataSocket] 4 Jan 2008 15:20:29.440 : Calling accept()
DEBUG [FTPActiveDataSocket] 4 Jan 2008 15:20:29.440 : accept() succeeded
DEBUG [FTPActiveDataSocket] 4 Jan 2008 15:20:29.440 : closeChild() succeeded
DEBUG [FTPActiveDataSocket] 4 Jan 2008 15:20:29.440 : close() succeeded
DEBUG [FTPClient] 4 Jan 2008 15:20:29.440 : Transferred 46592 bytes to remote host
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.456 : 226 Closing data connection.
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.456 : ListenOnAllInterfaces=true
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.456 : ---> PORT 10,46,37,31,9,236
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.456 : 200 PORT Command successful.
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.456 : ---> STOR rxt.ibt.ppcm.b0001.d0000001.doc.ind
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.456 : 150 File status okay; about to open data connection.
DEBUG [FTPActiveDataSocket] 4 Jan 2008 15:20:29.456 : Calling accept()
DEBUG [FTPActiveDataSocket] 4 Jan 2008 15:20:29.456 : accept() succeeded
DEBUG [FTPActiveDataSocket] 4 Jan 2008 15:20:29.456 : closeChild() succeeded
DEBUG [FTPActiveDataSocket] 4 Jan 2008 15:20:29.456 : close() succeeded
DEBUG [FTPClient] 4 Jan 2008 15:20:29.456 : Transferred 1148 bytes to remote host
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.472 : 226 Closing data connection.
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.472 : ListenOnAllInterfaces=true
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.472 : ---> PORT 10,46,37,31,9,237
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.487 : 200 PORT Command successful.
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.534 : ---> STOR rxt.ibt.ppcm.b0001.d0000003.doc.out
DEBUG [FTPControlSocket] 4 Jan 2008 15:20:29.534 : 150 File status okay; about to open data connection.
DEBUG [FTPActiveDataSocket] 4 Jan 2008 15:20:29.534 : Calling accept()
DEBUG [FTPActiveDataSocket] 4 Jan 2008 15:20:29.550 : accept() succeeded
DEBUG [FTPActiveDataSocket] 4 Jan 2008 15:20:29.550 : closeChild() succeeded
DEBUG [FTPActiveDataSocket] 4 Jan 2008 15:20:29.550 : close() succeeded