Sterling Commerce Connect 的 Apache Commons Net FTPClient 检索文件方法问题

发布于 2024-08-21 20:16:26 字数 811 浏览 4 评论 0原文

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

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

它已经运行了 3 年,自过去两周以来我们一直面临问题。错误发生在上面一行,并且是

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泅人 2024-08-28 20:16:26

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

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

这应该可以解决你的问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文