开发者

Download file through FTP by Quartz scheduler

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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜