Search code examples
c#sftpsharpssh

Check if file exist on SFTP remote server


The following code will download 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 check if the file file.txt exist on the remote server or not. How can I do this check?

I am using SharpSSH


Solution

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