15

我正在编写一个 JAVA 代码来使用 Apache Commons Net FTPClient 遍历 FTP 位置并在 Excel 文件中获取输出。代码正确执行了大约 5 分钟,但随后给出了 IOException:

org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received.  Server closed connection.

我正在使用 commons-net-3.0.1.jar。我做了一些研发并尝试过:

setDefaultTimeout(6000); 
setConnectTimeout(3000);
setSoTimeout(3000);
enterLocalPassiveMode();

和发送NOOP,但仍然得到同样的错误。

我要做的就是遍历一个目录,如果找到文件,则在 excel 中获取文件名和文件更新日期,否则如果找到目录,则进入并执行直到再次找到文件。

请帮助并询问是否需要任何其他信息。我是 JAVA 的新手。

4

2 回答 2

19

见这里: http: //kb.globalscape.com/KnowledgebaseArticle10142.aspx

    错误 421 服务不可用,正在关闭控制连接。
    错误 421 达到用户限制
    错误 421 您无权建立连接
    错误 421 已达到最大连接数
    错误 421 超出最大连接数

也许您没有重用连接,而是为每个请求使用一个新连接,用连接淹没服务器,直到它达到连接限制。尝试关闭您的连接或恢复它们。

于 2014-07-17T09:28:04.130 回答
3

For future reference..

If the solution by @fiffy didn't work, maybe try turning on the TLS (FTPS/Secure Connection), My server was set to only accept FTPS protocol, so it was rejecting my unencrypted connection, so turning on the TLS (FTPS) helped me solve the prob.

Note:- This error FTP response 421 received is very prominent in Netbeans since its also built in java.

于 2014-09-01T12:22:53.037 回答