1
我試過工作Ftp下載獨立應用程序,它工作正常。但是當我把它加入到web應用程序中的Quartz調度器中時,它就會陷入困境。通過Quartz調度程序通過FTP下載文件
這是我做的。
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(路徑)。我做錯了什麼?
檢查您是否必須使用主動或被動ftp,如果防火牆/網關阻止活動FTP,您只會阻止並可能最終超時 - 切換到被動FTP通常可以解決這個問題。 – nos 2011-01-05 08:43:01
同意nos,檢查以下FTPClient方法是否可以幫助您嘗試:http://commons.apache.org/net/api/org/apache/commons/net/ftp/FTPClient.html#enterLocalPassiveMode%28%29 – kvista 2011-01-05 11:53:23