【发布时间】:2019-06-07 07:34:10
【问题描述】:
我正在使用 apache commons-net FTPClient(版本 3.3),并且在我的一台客户端机器上产生了以下错误(我尝试在我的开发机器上重现错误但没有运气使用测试文件夹上的相同请求同一个服务器,同一个登录)
我有一个检查远程 FTP 服务器以获取 XML 文件形式的新请求的过程。列出所有这些文件后,我继续循环检查它们是否为 XML 格式。如果文件是这种格式,我首先通过将格式从 *.xml 更改为 *.xmlProcessing 来更改它们的名称,将它们检索到输入流,将它们解析为我的对象并在我的队列中创建一个请求,最后更改名称和将它们移动到用作存档的子文件夹中。
下载随机数量的文件后,我在下一个文件上调用retrieveFileStream 时卡住了,没有超时或IO 异常。
我已经设法从 FTP 服务器获取日志,但它只是说它无法打开数据连接
05.06.2019 12:45:45 - > RNFR /folder/file.xml
05.06.2019 12:45:45 - > 350 File exists, ready for destination name.
05.06.2019 12:45:45 - > RNTO /folder/file.xmlProcessing
05.06.2019 12:45:45 - > 250 file renamed successfully
05.06.2019 12:45:45 - > PORT *ports*
05.06.2019 12:45:45 - > 200 Port command successful
05.06.2019 12:45:45 - > RETR /folder/file.xmlProcessing
05.06.2019 12:45:45 - > 150 Opening data channel for file download from server of "/folder/file.xmlProcessing"
05.06.2019 12:45:45 - > 425 Can't open data connection for transfer of "/folder/file.xmlProcessing"
我已经尝试过不同的 FTP 模式。主动本地、远程、被动等(目前卡在被动本地模式)。
我已经尝试过数据超时,但看起来当我最终卡在其中一个文件上时,尽管我将超时设置为 30 秒,但该方法在该文件上花费了超过 1 分钟。
ftp = new FTPClient();
ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
ftp.connect(server, port);
int reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
throw new IOException("Exception in connecting to FTP Server");
}
ftp.login(user, password);
ftp.enterLocalPassiveMode();
ftp.setKeepAlive(true);
ftp.setDataTimeout(30000);
Collection<String> listOfFiles = listFiles(FOLDER_PATH);
for(String filePath : listOfFiles){
if (filePath != null && filePath.endsWith(".xml")) {
ftp.rnfr(folder + filePath);
ftp.rnto(folder + filePath + "Processing");
InputStream fileInputStream = ftp.retrieveFileStream(folder + filePath + "Processing");
ftp.completePendingCommand();
//Parsing file to an instance of my object and creating request
ftp.rnfr(folder + filePath + "Processing");
ftp.rnto(archiveFolder + filePath);
if(fileInputStream != null){
fileInputStream.close();
}
}
}
这是否更可能是 FTP 服务器、防火墙问题或其他原因造成的?
我在我的开发机器上运行了相同的代码,它处理了测试文件夹中的所有文件(大约有 400 个)我的承包商与远程服务器的通信实际上有问题吗?
【问题讨论】:
-
在远程服务器上的传输速度不是比在本地开发机器上更快吗(例如,因为连接速度更快)?
-
几乎可以肯定。我只有一台笔记本电脑。并且进程部署在高端机器上,可能和FTP服务器在同一个主机中心。