Ftp.GetList(string) and WildCards + Case-Insensitive Listing

0 votes
asked Mar 20, 2012 by AdvStpDev (270 points)
edited Mar 21, 2012

The documentation is clear about the support for wildcards in Sftp.GetList.

But in the case of Ftp, although wildcards seem t work, I don't see the documentation mentioning it. Also it has the following comments in the help file Ftp.GetList Method (String):

Caution: The meaning of the arguments argument is not defined by RFC and varies from server to server. Some servers interpret it as parameters to dir command, some as a filename, some ignore it and some report an error. Calling this method with arguments other than null is not recommended and will make your code incompatible with many FTP servers.

Questions:
1. Is WildCards supported in ftp.GetList(string) method? Should I be worried about the above warning?
2. How do I get a case-insensitive listing?
The wildcard listing in Ftp.GetList seems to be case-sensitive. Sftp class has an enumeration called SftpServerType. If in need case-insensitive listing, I set the SftpServerType to Windows. Unfortunately, Ftp class doesn't have a similar enumeration.

I am using FTP File Transfer Pack, .Net 2.0 Version.

Thanks.

Applies to: Rebex FTP/SSL

1 Answer

0 votes
answered Mar 21, 2012 by Lukas Pokorny (101,070 points)
edited Mar 21, 2012
 
Best answer

In Sftp.GetList(string) method (Rebex SFTP), wildcards are applied at the client side because the SFTP protocol doesn't support them. On the other hand, Ftp.GetList(string) (Rebex FTP) passes the argument to the server without any processing and the caution does in fact apply.

1) Ftp.GetList(string) only supports wildcards if the FTP server supports them. Almost all modern Windows-based and Unix-based FTP servers do, which means you should only be worried if you need a solution that should be compatible with rarer FTP servers as well.

2) Whether the listing is case sensitive depends only on the FTP server. As a general rule, Windows-based FTP servers are case insensitive and Unix-based FTP servers are case sensitive.

If you prefer a compatible solution and custom-defined case (in)sensitivity, cosider using Ftp.GetItems(string) method introduced in the latest vesion (2012 R1) of Rebex FTP, SFTP and File Transfer Pack. This performs the pattern matching at the client side. This might result in slower operation because a full listing is actually transferred to the client, but it's results are not server-dependent. Otherwise it's quite similar to Ftp.GetList(String) To give it a try, use the following code:

        using Rebex.Net;
        using Rebex.IO;
        ...

        // define a file set of *.txt in the current directory
        FileSet fileSet = new FileSet(".", "*.txt", TraversalMode.NonRecursive);

        // perform case-sensitive matching
        fileSet.IsCaseSensitive = true;

        // retrieve the listing
        FtpItemCollection list = ftp.GetItems(fileSet);

Note that the FileSet also makes it possible to match multiple patterns at the same time or exclude specific files/patterns from the listing.

commented Mar 21, 2012 by AdvStpDev (270 points)
edited Mar 21, 2012

Thanks Lukas for the prompt reply. This is really helpful.

...