3

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

Jakob K
  • 31
  • 1
  • 3
  • support HTTP proxy is the reason I choose [ftp4j](http://www.sauronsoftware.it/projects/ftp4j/) instead of other ftp client libraries. – LiuYan 刘研 Jun 08 '12 at 15:03
  • Indeed, I chose ftp4j because of the HTTP proxy. I don't think the issue is with the library, but with a configuration somewhere, but since I have control over neither FTP servern or proxy, it's difficult for me to pin down where the problem is – Jakob K Jun 08 '12 at 15:51
  • does other FTP client works? try use **[FileZilla](http://filezilla-project.org/)** (GUI) or **[lftp](http://lftp.yar.ru/)** (CLI) or **[wget](http://www.gnu.org/software/wget/)** (CLI) to help findout where's the problem. – LiuYan 刘研 Jun 08 '12 at 16:15
  • @LiuYan刘研 - I've just tried lftp I use "set ftp:proxy http://xx.xx.xx.xx:8080" to set the proxy address, and then "open -u username hostname" to connect, and this actually works! I can look around and download without a problem. Edit: Any ideas why lftp works, while ftp4j fails most of the time? – Jakob K Jun 08 '12 at 16:30
  • Update to above: it says "set ftp:proxy xx.xx.xx.xx:8080", but there's "http : //" in front of the IP address - that was missing from the comment. This means that I use HFTP (FTP over HTTP proxy) – Jakob K Jun 08 '12 at 16:39
  • You can use a computer which is not under NAT to determine if the server port is reachable. In china, our f**king government block HTTP 80/8080 port and some other well known ports if your IP address is not registered, so I must use an not well known port to serve HTTP/FTP services. So, if the server port is not reachable, consider either the port is not opened by a firewall or the port is blocked by SP. – LiuYan 刘研 Jun 09 '12 at 04:50
  • I solved this by discovering that we have an FTP proxy in addition to the HTTP proxy. This worked with no problems, so we stopped investigating the HTTP proxy problem. Thank you for your assistance however, it was helpful! – Jakob K Jun 12 '12 at 09:37

0 Answers0