Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
8.1k views
in Java FTP by (280 points)
Good afternoon,

I get a Read timed out Exception while trying to close the FileTransferInputStream. Downloading the data was successful.

The code is:

  ftp = new FileTransferClient();
            ftp.setRemoteHost(host);
            ftp.setUserName(user);
            ftp.setPassword(pw);
            ftp.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.PASV);
            ftp.connect();
            ftp.changeDirectory("incoming/test/");
            File f = File.createTempFile("temp", ".pdf");
            FileOutputStream fos = new FileOutputStream(f);
            com.enterprisedt.util.debug.Logger.setLevel(com.enterprisedt.util.debug.Level.ALL);
            StringBuffer s2 = new StringBuffer();
            FileTransferInputStream in = ftp.downloadStream("1.pdf");
            try {
                int ch = 0;
                while ((ch = in.read()) >= 0) {
                    s2.append((char)ch);
                }
            }
            finally {
                in.close(); // MUST be closed to complete the transfer
            }
            ftp.disconnect(true);
            System.out.println("Example complete");

The exception:
com.enterprisedt.net.ftp.ControlChannelIOException: Read timed out
at com.enterprisedt.net.ftp.FTPControlSocket.readLine(FTPControlSocket.java:1029)
at com.enterprisedt.net.ftp.FTPControlSocket.readReply(FTPControlSocket.java:1064)
at com.enterprisedt.net.ftp.FTPClient.validateTransfer(FTPClient.java:2471)
at com.enterprisedt.net.ftp.FTPInputStream.close(FTPInputStream.java:358)
at date_small.Main$4.run(Main.java:281)

The Debuginformation:
DEBUG [FTPControlSocket] 12 Aug 2010 21:36:33.187 : ---> PASV
DEBUG [FTPControlSocket] 12 Aug 2010 21:36:33.203 : 227 Entering Passive Mode (127,0,0,1,234,101).
INFO [FTPControlSocket] 12 Aug 2010 21:36:33.203 : Substituting server supplied IP (127.0.0.1) with remote host IP (127.0.0.1)
DEBUG [FTPControlSocket] 12 Aug 2010 21:36:33.203 : ---> RETR 1.pdf
DEBUG [FTPControlSocket] 12 Aug 2010 21:36:33.203 : 150 Opening BINARY mode data connection for 1.pdf (25639 bytes)
DEBUG [FTPInputStream] 12 Aug 2010 21:36:33.218 : Transferred 25639 bytes from remote host
ERROR [FTPControlSocket] 12 Aug 2010 21:36:43.734 : Read failed ('' read so far)

I really have no idea why this Error is happening every time I want to download a File and i'm hoping for help.

Kind regards
Sebastian

7 Answers

0 votes
by (162k points)
The server isn't sending the message to say the download is complete before it times out.

What timeout value do you have set? Try setting it to 60s (60,000 ms).
0 votes
by (280 points)
Thanks for the fast reply. But neither setting timeout to 60s nor setting it to 120s has any effect.
0 votes
by (280 points)
A timeout of 180 seconds is working. Not really nice, having the Threads 3 minutes open only waiting for a response from the server but...

thanks a lot
0 votes
by (162k points)
That's not very good. There's some problem there - it should never have to wait 3 minutes.

Does an ordinary download work fine? Maybe post a log for each - and make sure you are using the latest jar.
0 votes
by (280 points)
Sorry for answering so late, I was away for a few days. Downloading with FileZilla is working fine I'm using the latest free jar, 2.1.0 free.

The log for a transfer ist always like:

30.08.2010 09:32:24 date_small.EventListenerImpl replyReceived
INFO: Reply received: 220 ProFTPD 1.3.1 Server (*******) [127.0.0.1]
30.08.2010 09:32:24 date_small.EventListenerImpl commandSent
INFO: Command sent: ---> USER sgate
30.08.2010 09:32:24 date_small.EventListenerImpl replyReceived
INFO: Reply received: 331 Password required for sgate
30.08.2010 09:32:24 date_small.EventListenerImpl commandSent
INFO: Command sent: ---> PASS ********
30.08.2010 09:32:24 date_small.EventListenerImpl replyReceived
INFO: Reply received: 230 User sgate logged in
30.08.2010 09:32:24 date_small.EventListenerImpl commandSent
INFO: Command sent: ---> TYPE I
30.08.2010 09:32:24 date_small.EventListenerImpl replyReceived
INFO: Reply received: 200 Type set to I
30.08.2010 09:32:24 date_small.EventListenerImpl commandSent
INFO: Command sent: ---> CWD incoming/test/
30.08.2010 09:32:24 date_small.EventListenerImpl replyReceived
INFO: Reply received: 250 CWD command successful
30.08.2010 09:32:24 date_small.EventListenerImpl commandSent
INFO: Command sent: ---> PASV
30.08.2010 09:32:24 date_small.EventListenerImpl replyReceived
INFO: Reply received: 227 Entering Passive Mode (127,0,0,1,234,139).
30.08.2010 09:32:24 date_small.EventListenerImpl commandSent
INFO: Command sent: ---> RETR 4.pdf
30.08.2010 09:32:24 date_small.EventListenerImpl replyReceived
INFO: Reply received: 150 Opening BINARY mode data connection for 4.pdf (28946 bytes)
30.08.2010 09:32:24 date_small.EventListenerImpl bytesTransferred
INFO: Bytes transferred=28946
30.08.2010 09:35:24 date_small.EventListenerImpl replyReceived
INFO: Reply received: 226 Transfer complete
30.08.2010 09:35:24 date_small.EventListenerImpl commandSent
INFO: Command sent: ---> QUIT
30.08.2010 09:35:24 date_small.EventListenerImpl replyReceived
INFO: Reply received: 221 Goodbye.

after the last Byte is transferred, it's needing excatly 3 minutes for recieving the 226 Transfer complete Message.

A Filezilla Log looks like:

Antwort: 250 CWD command successful
Befehl: TYPE I
Antwort: 200 Type set to I
Befehl: PASV
Antwort: 227 Entering Passive Mode (127,0,0,1,234,191).
Befehl: RETR 6.pdf
Antwort: 150 Opening BINARY mode data connection for 6.pdf (28945 bytes)
Antwort: 226 Transfer complete
Status: Dateitransfer erfolgreich, 28.945 Bytes in 1 Sekunde
0 votes
by (280 points)
Strange, this delay occurs only if the file i'm downloading is a PDF. With .rar or .txt files the downloas works quite nicely.

Log:

30.08.2010 10:15:07 date_small.EventListenerImpl replyReceived
INFO: Reply received: 220 ProFTPD 1.3.1 Server (*******) [127.0.0.1]
30.08.2010 10:15:07 date_small.EventListenerImpl commandSent
INFO: Command sent: ---> USER sgate
30.08.2010 10:15:07 date_small.EventListenerImpl replyReceived
INFO: Reply received: 331 Password required for sgate
30.08.2010 10:15:07 date_small.EventListenerImpl commandSent
INFO: Command sent: ---> PASS ********
30.08.2010 10:15:07 date_small.EventListenerImpl replyReceived
INFO: Reply received: 230 User sgate logged in
30.08.2010 10:15:07 date_small.EventListenerImpl commandSent
INFO: Command sent: ---> TYPE I
30.08.2010 10:15:07 date_small.EventListenerImpl replyReceived
INFO: Reply received: 200 Type set to I
30.08.2010 10:15:07 date_small.EventListenerImpl commandSent
INFO: Command sent: ---> CWD incoming/test/
30.08.2010 10:15:07 date_small.EventListenerImpl replyReceived
INFO: Reply received: 250 CWD command successful
30.08.2010 10:15:07 date_small.EventListenerImpl commandSent
INFO: Command sent: ---> PASV
30.08.2010 10:15:07 date_small.EventListenerImpl replyReceived
INFO: Reply received: 227 Entering Passive Mode (127,0,0,1,234,187).
30.08.2010 10:15:07 date_small.EventListenerImpl commandSent
INFO: Command sent: ---> RETR test.txt
30.08.2010 10:15:07 date_small.EventListenerImpl replyReceived
INFO: Reply received: 150 Opening BINARY mode data connection for test.txt (11 bytes)
30.08.2010 10:15:08 date_small.EventListenerImpl bytesTransferred
INFO: Bytes transferred=11
30.08.2010 10:15:08 date_small.EventListenerImpl replyReceived
INFO: Reply received: 226 Transfer complete
30.08.2010 10:15:08 date_small.EventListenerImpl commandSent
INFO: Command sent: ---> QUIT
30.08.2010 10:15:08 date_small.EventListenerImpl replyReceived
INFO: Reply received: 221 Goodbye.

No delay at all.
0 votes
by (162k points)
Now that is strange ... something weird with the server?

Categories

...