我尝试使用 Ftp 下载独立应用程序,它工作正常。但是当我将其包含到 Web 应用程序中的 Quartz 调度程序中时,它就卡住了。
这就是我所做的。
public class FtpTransfer implements StatefulJob {
public void execute(JobExecutionContext arg0) throws JobExecutionException {
FTPClient ftp = new FTPClient();
FileOutputStream br = null;
try
{
ftp.connect("localhost");
ftp.login("admin", "admin");
String path = "alfresco/MYPUB/Admin/TMM/Pickup";
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
ftp.changeWorkingDirectory(path);
System.out.println("After Changing Directory path");
FTPFile[] ftpFile = ftp.listFiles(path);
System.out.println("After getting list of files");
System.out.println("Length : "+ftpFile.length);
System.out.println("----------------- Downloaded -------------");
for(FTPFile tempFtpFiles : ftpFile) {
br = new FileOutputStream("e:\\Downloaded\\"+tempFtpFiles.getName());
ftp.retrieveFile(tempFtpFiles.getName(), br);
System.out.println(tempFtpFiles.getName());
}
System.out.println("------------------------------------------");
}
catch(Exception exception) {
System.out.println("Error : "+exception);
} finally {
try {
if(br!=null){
br.close();
}
ftp.disconnect();
} catch(IOException e) {
e.printStackTrace();
System.out.println("Error : "+e);
}
}
}
}
当我启动服务器时,它会打印
After Changing Directory path
After Changing Directory path
After Changing Directory path
每 10 秒一次。但它不是从给定的路径下载文件。主要是程序没有越线 FTPFile[] ftpFile = ftp.listFiles(path)。我做错了什么?
最佳答案
感谢您的评论。我已经找到问题了。在lib中包含jakarta-oro.jar后,它工作正常。
关于java - Quartz调度器通过FTP下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4601552/