I try use ftp client in my application

first one I use org.apache.commons.net.ftp.FTPClient

but when running on linux server

can login to ftp server, can't get file list

return message is 425 Failed to establish connection.

if you close the firewall can be work

well, I try to change to sun.net.ftp.FtpClient

amazing thing happened

I can got file list

both are active modes, does anyone know why there is such a difference?

FTPClient ftpClient = new FTPClient(); ftpClient.connect("host"); ftpClient.login("account", "password"); ftpClient.listFiles("path"); // can't work if you not open firewall FtpClient ftp = FtpClient.create("host"); ftp.login("account", "password".toCharArray()); ftp.listFiles("path"); // even if you do not open the firewall can work 

1 Answer

It seems that the relevant difference is that sun.net.ftp.FtpClient defaults to using passive (PASV) mode, but org.apache.commons.net.ftp.FTPClient defaults to active.

At least, that is my reading of the respective source codes:

  • (line 79)
  • (line 491)

You should be able to confirm this by running:

FtpClient ftp = FtpClient.create("host"); ftp.login("account", "password".toCharArray()); ftp.enablePassiveMode(false); ftp.listFiles("path"); 

You should be able to use PASV mode (aka local passive mode) with the Apache FTP client; see the javadocs.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.