通过Quartz调度程序通过FTP下载文件

时间:2011-01-05 06:55:17

标签: java ftp network-programming quartz-scheduler

我尝试使用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秒。但它不是从给定的路径下载文件。 Mailnly程序没有越过FTPFile [] ftpFile = ftp.listFiles(path)。我做错了什么?

1 个答案:

答案 0 :(得分:1)

感谢您的评论。我发现了这个问题。在lib中包含 jakarta-oro.jar 之后,它的工作正常。

相关问题