Sterling Commerce Connect出现Apache Commons Net FTPClient retrievefile方法问题

Sterling Commerce Connect出现Apache Commons Net FTPClient retrievefile方法问题,ftp,apache-commons,connect,commerce,Ftp,Apache Commons,Connect,Commerce,我们一直在使用ApacheCommonsNetFTP类,通过代理连接到位于网络外部的Sterling commerce FTP网关,以获取文件。我们不列出文件,因为我们知道要拉取的文件的名称,所以我们使用下面的方法直接拉取它 布尔值isTransferred=ftp.retrieveFile(remoteFileName,outputFile) 它已经运行了3年,从过去2周起,我们就一直面临问题。错误发生在第行上方,并且 org.apache.commons.net.ftp.FTPConnect

我们一直在使用ApacheCommonsNetFTP类,通过代理连接到位于网络外部的Sterling commerce FTP网关,以获取文件。我们不列出文件,因为我们知道要拉取的文件的名称,所以我们使用下面的方法直接拉取它

布尔值isTransferred=ftp.retrieveFile(remoteFileName,outputFile)

它已经运行了3年,从过去2周起,我们就一直面临问题。错误发生在第行上方,并且

org.apache.commons.net.ftp.FTPConnectionClosedException:接收到ftp响应421。服务器已关闭连接。 org.apache.commons.net.ftp.ftp.\uu 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)

自上两周以来,我们断断续续地面临这些问题,不确定其根本原因是什么。双方都没有改变。有什么想法吗?可能是什么问题

谢谢,
Ravi

FTPClient默认使用“活动模式”,这是有问题的,因为它需要FTP客户端打开一个端口,以便FTP服务器重新连接。使用被动模式应该可以避免这个问题。连接并登录后,在FTP代码中添加以下行

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

这将解决您的问题。

FTPClient默认情况下使用“活动模式”,这是有问题的,因为它需要FTP客户端打开一个端口,以便FTP服务器重新连接。使用被动模式应该可以避免这个问题。连接并登录后,在FTP代码中添加以下行

FTPClient ftp = new FTPClient();
// connect and login code here
ftp.enterLocalPassiveMode();
这会解决你的问题