SFTP GetList wildcards?

0 votes
asked Apr 5, 2011 by Spored (150 points)
edited Apr 5, 2011

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
answered Apr 5, 2011 by Lukas Pokorny (126,910 points)
edited Apr 5, 2011
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();

        SftpItemCollection list = sftp.GetList("*.tar");
        foreach (SftpItem item in list)

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!

commented Apr 5, 2011 by Spored (150 points)
edited Apr 5, 2011

Works perfectly.

And glad I helped finding problem with documentation :).

Thank you.