Question

I am using apache commons net FTPSClient to connect to a local ftp (passive mode). The connection seems to hang after

> LIST
< 150 Opening ASCII mode data connection for /bin/ls.

I have added some logging to the FTPClient class to see where exactly it hangs. It is in this method: http://grepcode.com/file/repo1.maven.org/maven2/commons-net/commons-net/3.3/org/apache/commons/net/ftp/FTPClient.java#FTPClient.initiateListParsing%28org.apache.commons.net.ftp.FTPFileEntryParser%2Cjava.lang.String%29

The socket gets created and socket.isBound() returns true, as does socket.isConnected() whilst socket.isInputShutDown() returns false. All seems well until the ftp client actually tries to read from the inputstream, this hangs indefinately without any data forthcoming. Wireshark is not an option due to the use of SSL.

At this point (due to the socket state) I have ruled out firewall issues but I am at a loss what could be causing the hang. I assume it is server side and I can talk to the people running it but it would be helpful if I could tell them where to look.

UPDATE

I would appreciate an explanation if the question is downvoted or voted for close...It seems to me to be a perfect stackoverflow question.

Was it helpful?

Solution

With FTPS you have to use PROT P to make the data channel TLS or PROT C for a non-protected data channel. It might hang because client and server don't agree about the protection of the channel, e.g. the clients wait for non-encrypted data from the server while the server waits for a TLS Client Hello from the client to start encryption. So please check your communication for "PROT" command and the replies to it.

Other problems might be if the FTP server is behind a router or firewall. PASV mode is used when the client is behind a firewall, but will give problems if the server is behind a dumb firewall or NAT. Try if plain (e.g. non-TLS) FTP works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top