私はFtpのスタンドアロンアプリケーションをダウンロードしようとしましたが、正常に動作します。しかし、それをWebアプリケーションの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(path)という行を超えていませんでした。私は何を間違えたのですか?
アクティブまたはパッシブFTPを使用する必要があるかどうかを確認します。ファイアウォール/ネットゲートウェイがアクティブなFTPをブロックしている場合は、単に遮断して最終的にタイムアウトします。 – nos
nosと合意して、次のFTPClientメソッドが役立つかどうかを確認してください。http://commons.apache.org/net/api/org/apache/commons/net/ftp/FTPClient.html#enterLocalPassiveMode%28%29 – kvista