Quartz调度器通过FTP下载文件

发布于 2024-10-10 13:19:39 字数 1752 浏览 2 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还不是爱你 2024-10-17 13:19:39

感谢您的评论。我已经找到问题了。在lib中包含jakarta-oro.jar后,它工作正常。

Thanks for your comments. I have found the problem. After included jakarta-oro.jar in lib, its working fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文