0 votes
by (120 points)
edited

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
by (70.2k points)
edited

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).

...