Javaコードの編集バージョン:
FileSystemOptions opts = new FileSystemOptions();
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
// fileToMonitor is the FTP folder.
LOG.debug("Trying to resolve file " + fileToMonitor + "...");
FileObject fo = fileSystemManager.resolveFile(fileToMonitor, opts);
LOG.debug("File resolved, attempting to add to DefaultFileMonitor...");
DefaultFileMonitor monitor = createFileMonitor(processor);
// This line causes PORT and LIST commnads to be sent to the FTP server
monitor.addFile(fo);
LOG.debug("File successfully, added to DefaultFileMonitor");
ネットワークトラフィックを監視しましたが、FTPの場所がモニターに追加されると、サーバー上の2つのフォルダーにPORTコマンドとLISTコマンドが送信されるようです。問題は、それが(おそらく、呼び出し元のクライアントポートがなくなるまで)それを実行し続けることです。
FTPネットワークトラフィックの抜粋は次のとおりです。
50 0.312500 {TCP:2, IPv4:0} FTP FTP:Request from Port 12620,'PORT xxx,xxx,xxx,xxx,49,114'
51 0.312500 {TCP:2, IPv4:0} FTP FTP:Response to Port 12620, '200 PORT command successful.'
52 0.312500 {TCP:2, IPv4:0} FTP FTP:Request from Port 12620,'LIST tmp/dump'
<snipped>
270 1.750000 {TCP:2, IPv4:0} FTP FTP:Request from Port 12620,'PORT xxx,xxx,xxx,xxx,49,115'
271 1.750000 {TCP:2, IPv4:0} FTP FTP:Response to Port 12620, '200 PORT command successful.'
272 1.750000 {TCP:2, IPv4:0} FTP FTP:Request from Port 12620,'LIST tmp'
<snipped>
343 2.296875 {TCP:2, IPv4:0} FTP FTP:Request from Port 12620,'PORT xxx,xxx,xxx,xxx,49,116'
344 2.312500 {TCP:2, IPv4:0} FTP FTP:Response to Port 12620, '200 PORT command successful.'
345 2.312500 {TCP:2, IPv4:0} FTP FTP:Request from Port 12620,'LIST tmp/dump'
<snipped>
560 3.687500 {TCP:2, IPv4:0} FTP FTP:Response to Port 12620, '226 Transfer complete.'
566 4.031250 {TCP:2, IPv4:0} FTP FTP:Request from Port 12620,'PORT xxx,xxx,xxx,xxx,49,118'
567 4.031250 {TCP:2, IPv4:0} FTP FTP:Response to Port 12620, '200 PORT command successful.'
568 4.031250 {TCP:2, IPv4:0} FTP FTP:Request from Port 12620,'LIST tmp'
<repeat>
その一部は、LISTコマンドからの応答です。コマンドは同じフォルダに対して繰り返されますが、ポートは毎回変更されることに注意してください。これらの場所にファイルがない場合、これは発生しません。
この動作の原因と、送信者がリストを1回だけ取得するように変更するにはどうすればよいですか?
編集:問題をFileObjectのgetChildren()メソッドに絞り込みました。
これは私が見つけた唯一のインターネットリファレンスです:http: //mail-archives.apache.org/mod_mbox/commons-user/201005.mbox/%3C4c03ed10.0d01df0a.53c3.059c@mx.google.com%3E