Check if file exist on SFTP remote server

Illep picture Illep · Jun 9, 2012 · Viewed 14.8k times · Source

The following code will down the file named file.txt from the SFTP remote server to the local machine.

 sftp.Get("/usr/mine/file.txt" , "C:/Folder/");

What i want to do is to Check if the file file.txt exist in the remote server or not. How can i do this check. Help

I am using SharpSSH

Answer

Bryan Crosby picture Bryan Crosby · Jun 9, 2012

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.