Check if file exist on SFTP remote server
15,820
Solution 1
You could consider just taking the small hit and attempting to download the file. If it doesn't exist, an exception should be thrown and you can just catch it and move on. Checking for a file's existence is a volatile situation so in the majority of cases it's best to try and perform your action.
Solution 2
This should do the trick.
using (var sftp = new SftpClient(host, username, password))
{
try
{
sftp.Connect();
MessageBox.Show(sftp.Exists(remoteDirectory).ToString());
}
catch (Exception Sftpex)
{
MessageBox.Show(Sftpex.ToString());
}
}
Comments
-
Illep almost 2 years
The following code will down the file named
file.txt
from theSFTP remote server
to thelocal machine
.sftp.Get("/usr/mine/file.txt" , "C:/Folder/");
What i want to do is to Check if the file
file.txt
exist in theremote server
or not. How can i do this check. HelpI am using
SharpSSH