Why does DefaultFileMonitor keep listing the files in my FTP location in a loop?
An edited version of the java code:
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");
I monitored the network traffic and it seems that when the FTP location is added to the monitor, it sends PORT and LIST commands to two folders on the server. The problem is that it keeps doing it (presumably till it runs out of client ports to call from?.
Here's an excerpt of the FTP network traffic:
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, IP开发者_运维问答v4: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>
The part is the response from the LIST command. Note that the commands are repeated for the same folders but the port changes each time. This does not occur when there are no files at those locations.
What causes this behaviour and how can I change it so that only sends retrieves the listing once?
Edit: I've narrowed down the problem to the getChildren() method on the FileObject.
This is the only internet reference I could find: http://mail-archives.apache.org/mod_mbox/commons-user/201005.mbox/%3C4c03ed10.0d01df0a.53c3.059c@mx.google.com%3E
I've discovered that this is a bug in FTPFileObject in VFS.
https://issues.apache.org/jira/browse/VFS-114?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
I built another jar from the latest source code and the problem went away.
精彩评论