dsknjksad
dsknjksad

Reputation: 83

Get a whole FTP directory listings recursively in one call possible to reduce time

Get a whole FTP directory listings recursively in one call if possible to reduce time using possibly Apache Commons API. Right now I have to call it multiple times to get all the directory listings is there any solutions for that.

Upvotes: 0

Views: 738

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202262

There's no standard way to request recursive directory listing from remote server in "one call".

So even if the Apache Common Net (or any other library) had a single call API to request recursive directory listing, it would internally have to do the same recursive algorithm, as for example here:
Retrieve all sub folders contents using Java Apache Commons Net library


Some FTP servers support a non-standard request for recursive listing.

For example ProFTPD has -R switch to LIST command (and similar) to list the directories recursively.

In Apache Commons Net you can inject that switch by simply prepending it to the path:

ftpClient.listFiles("-R " + remotePath);

But you can use that only if you know for sure that you are connected to ProFTPD.


I do not know of any other FTP server with similar functionality. With other FTP servers you can optimize the listing by using multiple parallel connections.

If you have a choice of protocols, consider using WebDAV, as that's the only file transfer protocol I know of that supports recursive directory listing.


Similar question:
How to list the sub directories in a Windows FTP server?

Upvotes: 1

Related Questions