我已经使用org.apache.commons.net.ftp.FtpClient来创建一个可靠的FTP类,它应该可以并行下载多个文件,然后重试失败。
奇怪的是,我似乎无法让代码识别失败。例如,如果我在传输过程中拉动我的以太网电缆,则代码似乎会继续阻止:
client.retrieveFile(nextFile, ftpOutputStream);线。有人能告诉我为什么它会阻止这行,而不是返回false或抛出异常?我错过了设置超时或类似的东西吗?
try {
OutputStream ftpOutputStream = new FileOutputStream(fileName);
System.out.println("Attempting to retrieve file [" + nextFile + "].");
success = iclient.retrieveFile(nextFile, ftpOutputStream);
System.out.println("Returned from retrieving file [" + nextFile + "].");
ftpOutputStream.close();
}
//Can fail due to FTPConnectionClosedException, CopyStreamException, or IOException. In any case, best course
//of action is to simply create a new connection, log in again, and change back to target directory.