【发布时间】:2013-04-17 08:53:21
【问题描述】:
我使用 sauronsoftware.ftp4j.FTPClient 从 FTP 服务器进行预定的文件下载。 我的问题是当客户端从它下载文件时 FTP 服务器突然死掉了。 这就是我所做的:
for (FTPFile remoteFile : remoteFiles) {
String remoteFileName = remoteFile.getName();
String localPath = ftpDir.getLocalPath() + remoteFileName;
log.debug("Downloading remote file {} to local path {}", remoteFileName, localPath);
try {
client.download(remoteFileName, new File(localPath));
if (!ftpDir.isLeaveFilesOnServer()) {
//Delete remote file
client.deleteFile(remoteFileName);
}
} catch (IllegalStateException e) {
log.error("FTPException ",e);
fcr.addErrorFile(remoteFileName);
} catch (IOException e) {
log.error("FTPException ",e);
问题在于 download(...) 由单独的线程运行,当 FTP 服务器死机时,该线程继续运行,就像永远一样。有没有办法解决这个问题,或者我应该使用另一个可以处理这种情况的 FTP 客户端?
【问题讨论】:
-
你能用
commons-net吗? commons.apache.org/proper/commons-net/examples/ftp/…
标签: java ftp ftp-client ftp4j