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