0 votes
by (150 points)
edited

Even though the SFTP protocol does not support using wildcards to filter its directory listings, this feature was requested so often that we simply had to add it to the GetList method and its variants. How do we do it? It's simple - all the filtering is done at the client side. Of course, this won't help you speed up the listing if you have thousands of files in a directory, but at least you would be able to limit the listing scope easily.

As I can see there should be an option for GetList to show only filtered files. For example .tar or partofname*.tar.

I just can't find how to make this work. It only has one possible parameter and that is the Path of where to list files from.

Basicly I need to list all files from a folder or only ones that match the wildcard filter.

Can't this be done?

Thank you.

Applies to: Rebex SFTP

1 Answer

0 votes
by (147k points)
edited
 
Best answer

GetList method's "path" argument actually does accept wildcards, but it looks like we failed to document it. The following code should work, however:

        Sftp sftp = new Sftp();
        sftp.Connect(...);
        sftp.Login(...);

        SftpItemCollection list = sftp.GetList("*.tar");
        foreach (SftpItem item in list)
        {
            Console.WriteLine(item.Name);
        }

And this works as well:

        SftpItemCollection list = sftp.GetList("/home/myusername/partofname*.tar");

Thanks for letting us know about the missing documentation for this feature!

by (150 points)
edited

Works perfectly.

And glad I helped finding problem with documentation :).

Thank you.

...