Question

We are writing our own FTPS client using apache.commons.net v.2.2 and we've been trying to use listNames() in apache.commons.net.ftp.FTPClient but it is timing out in apache.commons.net.ftp.FTPListParseEngine.java line 152

    String line = this.parser.readNextEntry(reader);

We need our client to use TLS to authenticate and then drop to CCC mode before transferring the data. We are able to connect to the server and get the current working directory, but then the LIST/RETR commands time out. This is the log of our current implementation:

FTPS: Connecting to: XXXXXXXXXXXXXXXXX.com
FTPS: REPLY: 220 UNAUTHORIZED ACCESS TO THIS SYSTEM IS STRICTLY PROHIBITED.
FTPS: COMMAND: AUTH TLS
FTPS: REPLY: 234 AUTH TLS-C/TLS OK.
FTPS: Switching to passive mode in the middle of a session
FTPS: Logging in with user: XXXXXXXXX
FTPS: COMMAND: USER XXXXXXXXXXXX
FTPS: REPLY: 331 Password required for XXXXXXXXXXX.
FTPS: COMMAND: PASS **********
FTPS: REPLY: 230 Connect:Enterprise UNIX login ok, access restrictions apply.
FTPS: COMMAND: PBSZ 0
FTPS: REPLY: 200 PBSZ 0 OK.
FTPS: COMMAND: PROT P
FTPS: REPLY: 200 PROT P OK, data channel will be secured.
FTPS: Dropping to CCC mode
FTPS: COMMAND: CCC
FTPS: REPLY: 200 CCC Context Enabled.
FTPS: Setting Transfer Type to Binary
FTPS: COMMAND: TYPE I
FTPS: REPLY: 200 Type set to I.
FTPS: COMMAND: SYST
FTPS: REPLY: 215 UNKNOWN Type: L8
ftpClient.getSystemType() UNKNOWN Type: L8
FTPS: COMMAND: PWD
FTPS: REPLY: 257 "/XXXXXXXXXXXXX" is current directory.
FTPS: COMMAND: PASV
FTPS: REPLY: 227 Entering Passive Mode (XXX,XXX,XXX,XXX,XXX,XXX)
FTPS: COMMAND: LIST
FTPS: REPLY: 150 Opening BINARY mode data connection for ...
FTPS: java.lang.RuntimeException: java.net.SocketTimeoutException: Read timed out

In Wireshark we notice that other client sends a FTP-DATA packet right after opening a data connection, but in our implementation we don't send such packet. We think this may be the cause of the problem, but we're unsure how to fix it.

Was it helpful?

Solution

I'd ask for the code you're actually running for more details.

But as a preliminary response, since I had similar issues, check that apache commons is not really building a request in an object oriented fashion but rather sending each command to the server as you call it (e.g. calling ftpClient.enterLocalPassiveMode() will send the PASV right away), so that might create a few confusions. In that regard, the more likely error in this situations is not entering passive mode at the right time (after connect, before login).

If listnames doesn't work probably nothing works.

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