views:

471

answers:

2

Hi All,

We have been using apache commons net FTP classes to connect using a proxy to a Sterling commerce FTP gateway located outside our network to pull files. We do not list the files since we know the name of the file to be pulled so we pull it directly using the below method.

boolean isTransferred = ftp.retrieveFile(remoteFileName, outputFile);

It was working since 3 years and we have been facing issues since last 2 weeks. The error occurs at above line and is

org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received. Server closed connection. org.apache.commons.net.ftp.FTP.__getReply(FTP.java:347) org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:450) org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:478) org.apache.commons.net.ftp.FTPClient.openDataConnection(FTPClient.java:476) org.apache.commons.net.ftp.FTPClient.retrieveFile(FTPClient.java:1228)

We are facing these issues intermittently since last 2 weeks and not sure what could be the root cause of it. Nothing has changed on the either side. Any ideas what could be the issue?

Thanks, Ravi

A: 

Hi, Would you please explain how did you configure the FTPClient to work with the proxy ? I'm facing this problem now.

Thanks a lot, Hassan

Hassan
A: 

FTPClient uses 'active mode' by default, which is problematic as it requires FTP client to open a port for FTP server to connect back. Using a passive mode should circumvent this issue. After connecting and logging in, add the following line in your FTP code.

FTPClient ftp = new FTPClient();
// connect and login code here
ftp.enterLocalPassiveMode();

This should fix your problem.

nanda