commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knepp, Ethan" <>
Subject RE: [NET] FTPClient - retrieveFile() never returns
Date Tue, 27 Jul 2004 14:03:27 GMT
Hello David,

Implementation included a simple FTPUtil class that wrapped the FTPClient
class and its methods.  I have a single TimerTask that utilizes this FTPUtil
class and catches all exeptions.

If you call the FTPClient.getSoTimeout() you will notice that it is set to
0.  Well my solution was to use the FTPClient.setSoTimeout().  So if I would
set this value and the FTP server I established a connection with never
responds(like you are behind a poorly implemented or crippled firewall), the
low-level socket will throw a SocketException which would be caught by my
TimerTask.  The TimerTask would close the connection gracefully just as if
the connection was closed prematurely.

You can only call the setSoTimeout() after establishing a connection to a
FTP server.  I set my timeout to 300000 ms in my production code, but tried
lower timeouts like 10 seconds just to proved that it would work.  It all
looked great in my unit tests and I figured I solved the issue...

Now the disappointing part is that my fix was introduced into my production
code before the weekend and the same thing happened again, my TimerTask that
downloads the files just stopped and the SocketException was never thrown.

I am at a loss at this point.

I wish there were more examples and documentation regarding the extra
FTPClient methods.  I don't feel like learning the RFCs for FTP and Sockets
just so I can understand this API.  Maybe I can find some examples from
before Jakarta acquired this API that can explain this issue.


-----Original Message-----
From: David Wynter []
Sent: Monday, July 26, 2004 11:00 AM
To: Jakarta Commons Users List
Subject: RE: [NET] FTPClient - retrieveFile() never returns

Hi Ethan,

I too am having a similar problem. But I have an additional exception caught
	                } catch (FTPConnectionClosedException e)

But this is not thrown either. The ftpclient just sits there for hours. It
is not something that is easy to debug because it happens so infrequently.

Did you get around it?

My thoughts are to add another thread to timeout on and then to the listener
a method for killing the current connection.


-----Original Message-----
From: Knepp, Ethan []
Sent: 16 July 2004 15:23
To: ''
Subject: [NET] FTPClient - retrieveFile() never returns

I have been using Commons/Net's FTPClient for about 9 months now.  Its
awesome!  I am utilizing the retrieveFile(String string, OutputStream
outputStream) method for retrieving files.  I am retrieving zip files (avg
1MB in size) on a periodic (15min) basis and storing them on localhost
(Solaris 8) for further processing.  These zip files are generated and
stored by another company on a remote FTP Server (Windows).

Here is my wrapper around the FTPClient's(ftpConn) retrieveFile():

    public boolean retrieveFile(String fileName, OutputStream fileOutput) {
        boolean fileRetrieved = false;

        if (!ftpConn.isConnected()) {

        if (ftpConn.isConnected()) {

            try {

                fileRetrieved = ftpConn.retrieveFile(fileName, fileOutput);

            } catch (IOException ioe) {

                log.warn("FTPUtil - retrieveFile(): ", ioe);



        return fileRetrieved;

Recently my process that is retrieving the zip file seems to hang at
'fileRetrieved = ftpConn.retrieveFile(fileName, fileOutput);'.  If it
entered the 'this.reconnect()' I would see log messages stating entry, but I
don't so its not entering that method.  I don't see a IOException being
throw and the method never returns.  It isn't hanging on a regular basis
either, sometimes it takes 1 -2 days to occur.  The most recent encounter
was 6 days before a hang was encountered.  I see that the zip file is being
created locally from the outputStream, but it remains at 0K in size even
through the server file is 1MB.

I also performed the following after a hang has occured:
'netstat -a | grep remoteservername'
tcp        0      0    remoteservername:ftp ESTABLISHED

Does anyone have any ideas?


Ethan Knepp
Software Engineer
C-COR Incorporated

To unsubscribe, e-mail:
For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message