I'm using it.sauronsoftware.ftp4j to connect to an FTP server over the internet on port 21.
I'm connecting through a HTTP proxy, so I'm using the HTTPTunnelConnector.
I am able to connect and login to the FTP and set the mode to passive without problem
Now, when I try to download a file, or LIST files, or anything else that requires a data connection, I get a "425 Can't open data connection" from the FTP server. So, I'm able to establish the regular FTP connection, but the data connection is a problem.
Now, what puzzles me is that 10-15% of the time, the data connection actually goes through, and I'm able to download the file! When I rerun my program immediately after, it fails again with the 425 error code, and continues to do so until it magically works again.
This makes me think that it might be a port issue - that the data connection is stopped by a blocked port, and sometimes it is lucky enough to find an open port through which it can connect - but this is an uneducated guess.
Has anyone experienced something similar? Does my guess, that it's a port issue either in the HTTP proxy or perhaps in a firewall in front of the FTP server, sound correct?
Edit: I attached an FTPCommunicationListener to the client. Here is the communication log (censored for IP adresses, usernames and passwords)
Connected, logging in
Sent: USER username
Received: 331 Password required for username
Sent: PASS password
Received: 230 Logged on
Sent: FEAT
Received: 211-Features:
Received: MDTM
Received: REST STREAM
Received: SIZE
Received: MLST type*;size*;modify*;
Received: MLSD
Received: AUTH SSL
Received: AUTH TLS
Received: PROT
Received: PBSZ
Received: UTF8
Received: CLNT
Received: MFMT
Received: 211 End
Sent: OPTS UTF8 ON
Received: 200 UTF8 mode enabled
Sent: TYPE A
Received: 200 Type set to A
Sent: PASV
Received: 227 Entering Passive Mode (xx,xx,xx,xx,xx,xx)
Sent: REST 0
Received: 350 Rest supported. Restarting at 0
Sent: RETR /directory/file.csv
Received: 425 Can't open data connection.
it.sauronsoftware.ftp4j.FTPException [code=425, message= Can't open data connection.]
at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3330)
at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3213)
at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3078)
at FtpTest.getFileOutputStream(FtpTest.java:131)
at FtpTest.main(FtpTest.java:18)
Sent: QUIT Received: 221 Goodbye