A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/robinrodricks/FluentFTP/wiki/Directory-Listing below:

Directory Listing · robinrodricks/FluentFTP Wiki · GitHub

Tip: For detailed documentation refer to the IntelliSense tips that appear when you call a given API method.

How does GetListing() work internally?
  1. When you call GetListing(), FluentFTP first attempts to use machine listings (MLSD command) if they are supported by the server. These are most accurate and you can expect correct file size and modification date (UTC). You may also force this mode using client.ListingParser = FtpParser.Machine, and disable it with the FtpListOption.ForceList flag. You should also include the FtpListOption.Modify flag for the most accurate modification dates (down to the second).

  2. If machine listings are not supported we fallback to the appropriate OS-specific parser (LIST command), listed below. You may force usage of a specific parser using client.ListingParser = FtpParser.*.

  3. And if none of these satisfy you, you can fallback to name listings (NLST command), which are much slower than either LIST or MLSD. This is because NLST only sends a list of filenames, without any properties. The server has to be queried for the file size, modification date, and type (file/folder) on a file-by-file basis. Name listings can be forced using the FtpListOption.ForceNameList flag.

Note: Some FTP servers return no answer when listing an empty folder, so the client has no socket on the other side to communicate with. These exceptions are internally caught and an empty file listing is returned. If you need to check the implementation of this, search for all instances of FtpMissingSocketException in the FluentFTP project.

How does GetListing() return a recursive file listing?

In older versions of FluentFTP, we assumed that all servers supported recursive listings via the LIST -R command. However this caused numerous issues with various FTP servers that did not support recursive listings: The GetListing() call would simply return the contents of the first directory without any of the child directories included.

Therefore, since version 20.0.0, we try to detect the FTP server software and if we determine that it does not support recursive listing, we do our own manual recursion. We begin by assuming that all servers do not support recursive listing, and then whitelist specific server types.

If you feel that GetListing() is too slow when using recursive listings, and you know that your FTP server software supports the LIST -R command, then please contribute support for your server:

  1. Locate your FTP server type exists in the FtpServer enum.

  2. Update FtpClient.RecursiveList() to return true for your server type.

Can I filter file listings using wildcards?

Yes, if your FTP server supports it.

Different FTP (RFC 959) server implementations have taken various liberties in implementing wildcards, and to which degree. The wildcard functionality that you can achieve today, currently depends entirely on the server that you are connecting to.

Wildcards work when the server supports them. You just need to find the right way to code it, and do some experiments to see what works and what does not.

Example using MSLD on ProFTPD

Here is an example, using an up-to-date ProFTPD server and the MSLD FTP command.

client.Connect();
var item = client.GetListing("*.bin");
client.Disconnect();

FTP logs:

...
Command:  PWD
Response: 257 "/home/mike" is the current directory [<1ms]
>         GetListing("*.bin", Auto)
Command:  PASV
Status:   Waiting for response to: PASV
Response: 227 Entering Passive Mode (192,168,1,109,154,73). [1ms]
Status:   Connecting to IP #1= ***:39497
Command:  MLSD /home/mike/*.bin
Response: 550 /home/mike/*.bin: No such file or directory [<1ms]
...

As you can see, on ProFTPD, MLSD with wildcards is rejected.

Example using LIST on ProFTPD

But if you code this which executes the LIST FTP command:

var item = client.GetListing("*.bin", FtpListOption.ForceList);

you will get:

...
Command:  LIST /home/mike/*.bin
Response: 150 Opening BINARY mode data connection for file list [<1ms]
+---------------------------------------+
Listing:  -rw-r--r--   1 mike     mike            6 Sep 18  2022 /home/mike/test.bin
-----------------------------------------

and the list items are populated correctly.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4