Rebex.net SFTP - Any Files at the SFTP

0 votes
asked May 10, 2011 by Rodney Liedtke (120 points)
edited May 10, 2011

Hello,

I need a function to ask the Server, for any Files, not a special File.

test = client.FileExists("/home/test/*")

With this function the Boolean test = False...

Hope you can help :(

Applies to: Rebex SFTP

1 Answer

0 votes
answered May 10, 2011 by Lukas Matyska (60,690 points)
edited May 10, 2011

The FileExists method doesn't accept wildcards in path, but you can easily write a method using the GetList method as follows:

private static bool FileExists(Sftp sftp, string mask)
{
    foreach (SftpItem item in sftp.GetList(mask))
    {
        if (item.IsFile)
            return true;
    }
    return false;
}

Please note this method can be slow if the remote directory contains a lot of items, because it always retrieves whole directory listing (this is a limitation of the SFTP protocol itself).

...