gpt4 book ai didi

FTPClient SocketTimeoutException 读取超时

转载 作者:行者123 更新时间:2023-12-02 14:14:53 25 4
gpt4 key购买 nike

我有一个给定的 FTP 服务器。我可以通过 WinSCP 和其他程序连接到服务器。我已经通过 Java 连接到服务器,但过了一会儿我无法连接。根据 WinSCP,我可以一直连接。现在的问题是服务器是问题的原因还是程序的原因。

这是我的代码:

private FTPClient ftpClient = null;

public FtpServerConnector() throws Exception {
ftpClient = new FTPClient();
ftpClient.connect(url);
ftpClient.login(username, password);
}

public List<FTPFile> getDirectory(String directoryPath) throws Exception {
FTPFile[] files = ftpClient.listFiles(directoryPath);
List<FTPFile> result = new ArrayList<FTPFile>();
for (FTPFile ftpFile : files) {
if (ftpFile.getTimestamp().getTime().getTime() >= Long.parseLong("1451606400000")) {
result.add(ftpFile);
}
}
return result;
}

public static void main(String[] args) {
try {
FtpServerConnector ftpServerConnector = new FtpServerConnector();
List<FTPFile> folders = ftpServerConnector.getDirectory("/");
for (FTPFile ftpFile : folders) {
System.out.println(ftpFile.getName());
}
} catch (Exception e) {
e.printStackTrace();
}
}

有一个异常(exception):

java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:161)
at java.io.BufferedReader.read(BufferedReader.java:182)
at org.apache.commons.net.io.CRLFLineReader.readLine(CRLFLineReader.java:58)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:314)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:483)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:608)
at org.apache.commons.net.ftp.FTP.port(FTP.java:932)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:812)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:759)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3293)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3271)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2930)
at com.kianaanalytics.eventManagement.util.FtpServerConnector.getDirectory(FtpServerConnector.java:38)
at com.kianaanalytics.eventManagement.util.ImportWorker.getAllNewFairFolders(ImportWorker.java:19)

最佳答案

该目录内似乎有“太多”文件 - 太长而引发 SocketTimeout 异常。

您没有提到您在 FTP 客户端中使用的是什么版本,这个问题似乎处理类似的事情 - 如果版本低于 3.4,我会考虑升级版本。

https://issues.apache.org/jira/browse/NET-552

关于FTPClient SocketTimeoutException 读取超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42137740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com