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:
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