views:

209

answers:

1

I'm having trouble disconnecting from a ftp-server, using the enterprisedt java ftp framework.

I can simply not call disconnect() on a FileTransferClient object without getting an error.

I do not do anything, besides connecting to the server, and then disconnecting:

        // create client
        log.info("Creating FTP client");
        ftp = new FileTransferClient();

        // set remote host
        log.info("Setting remote host");
        ftp.setRemoteHost(host);
        ftp.setUserName(username);
        ftp.setPassword(password);

        // connect to the server
        log.info("Connecting to server " + host);
        ftp.connect();
        log.info("Connected and logged in to server " + host);

        // Shut down client
        log.info("Quitting client");
        ftp.disconnect();

        log.info("Example complete");

When running this, the log reads:

INFO [test] 28 maj 2010 16:57:20.216 : Creating FTP client
INFO [test] 28 maj 2010 16:57:20.263 : Setting remote host
INFO [test] 28 maj 2010 16:57:20.263 : Connecting to server x
INFO [test] 28 maj 2010 16:57:20.979 : Connected and logged in to server x
INFO [test] 28 maj 2010 16:57:20.979 : Quitting client
ERROR [FTPControlSocket] 28 maj 2010 16:57:21.026 : Read failed ('' read so far)

And the stacktrace:

com.enterprisedt.net.ftp.ControlChannelIOException: Connection reset
at com.enterprisedt.net.ftp.FTPControlSocket.readLine(FTPControlSocket.java:1029)
at com.enterprisedt.net.ftp.FTPControlSocket.readReply(FTPControlSocket.java:1089)
at com.enterprisedt.net.ftp.FTPControlSocket.sendCommand(FTPControlSocket.java:988)
at com.enterprisedt.net.ftp.FTPClient.quit(FTPClient.java:4044)
at com.enterprisedt.net.ftp.FileTransferClient.disconnect(FileTransferClient.java:1034)
at test.main(test.java:46)

It should be noted, that I without problems can connect, and do stuff with the server, like getting a list of files in the current working directory. But I cant, for some reason, disconnect! I've tried using both active and passive mode.

The above example is by the way copy/pasted from their own example. I cannot fint ANYTHING related to this by doing a Google-search, so I was hoping you have any suggestions, or experience with this issue.

A: 

Try enabling the traces with

com.enterprisedt.util.debug.Logger.setLevel(com.enterprisedt.util.debug.Level.DEBUG);

That will let you observe the communication between the library and the ftp server.

Try opening a connection to the ftp server with a command line client. Connect, log in, verify that is all working. Then type quot quit. That sends an explicit quit command to the ftp server. You should get either a 221 or a 226 response. If you get any other code, or if the connection is just closed, then you're up against a non-compliant FTP server.

If that's the case, you can also try using disconnect(true) as that just closes connections rather than attempting a graceful shutdown.

Devon_C_Miller
Non-compliant as in not understanding that quit command?Ill give it a try, thx!
Frederik Wordenskjold
I get a 221 response, so I guess there is nothing wrong with the server. disconnect(true) works, but it annoys me that it just closes everything. I guess I can just implement the functionality of disconnect() myself, but it is nevertheless annoying to know there is some kind of bug you dont know how to fix :S
Frederik Wordenskjold