Quantcast
Channel: SSH.NET Library
Viewing all articles
Browse latest Browse all 2955

Commented Issue: Remote File exists not working [1574]

$
0
0
I've tried to use sftp.Exists(String) do not work for files. Already tested for file and for directory. Directory work well, but files are not recognized.
Comments: ** Comment from web user: oeriksen **

In my project I have created the following little function and I havn't had any troubles with servers I connect to. SftpClient.GetAttributes() is using RequestLStat like I mentioned in my earlier comment. In my opinion it's better than the solution mmoufakkir2 is talking about which is from an earlier version of SshNet that was replaced because some server didn't close the file handle which caused problems when you wanted to delete the file. And it's better than current solution which doesn't work on all servers.
```
public bool Exists(string remotefilepath)
{
try
{
_sftpClient.GetAttributes(remotefilepath);
}
catch (SftpPathNotFoundException)
{
return false;
}
return true;
}
```


Viewing all articles
Browse latest Browse all 2955

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>