Quartz调度器通过FTP下载文件
我尝试使用 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)。我做错了什么?
I tried working Ftp download stand alone application and it works fine. But when I included that into Quartz scheduler in web application, it stucks.
Here is what I did.
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);
}
}
}
}
When I start the server, It prints
After Changing Directory path
After Changing Directory path
After Changing Directory path
Every 10 secs. But It is not downloading the files from the path given. Mailnly the program didn't crossed the line FTPFile[] ftpFile = ftp.listFiles(path). What did I do wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢您的评论。我已经找到问题了。在lib中包含jakarta-oro.jar后,它工作正常。
Thanks for your comments. I have found the problem. After included jakarta-oro.jar in lib, its working fine.