Skip to content
Advertisement

Why can I retrieve file names but not file objects from the FTP server?

I’m trying to access files on an FTP server embedded in specialised hardware with the Apache Commons Net library. For some reason listNames() works, but listFiles() does not.

The documentation for the hardware is very limited, but it does at least say that active mode has to be used. Connection to the hardware is made over a local WiFi network with no Internet access. The code below runs from within an Android app.

JavaScript

The output:

JavaScript

Judging by the error code 425, I suspect that there’s some issue related to active/passive mode, but can’t see how to clear it.

  • I have confirmed that the server is accessible and the files are browseable via the Turbo Client app on Android.
  • I have tried all the different possible FTPClientConfig options (e.g. FTPClientConfig.SYST_UNIX).

Advertisement

Answer

Martin Prikryl’s comments put me on the right track: calling setUnparseableEntries() caused listFiles() to start returning FTPFile objects that in turn returned usable information for getRawListing().

I’d already tried setUnparseableEntries() but I tried it again and this time, for some reason, it worked – so it must have needed some other setting to be made (possibly enterLocalActiveMode()) that wasn’t active at the time I initially tried it. Whatever the reason, listFiles() now returned a non-empty array.

I then extended ConfigurableFTPFileEntryParserImpl to create my own parser, so that I could use getName(), getSize() and isDirectory() on the FTPFile objects.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement