C# SFTP No Such File
If anyone else runs into this issue, it turns out that any of the methods such as ChangeDirectory and UploadFile expect a path relative to the WorkingDirectory
property. As a result, I fixed my issue by changing it to
client.ChangeDirectory(@"/other_directory");
Hope that helps someone else
Related videos on Youtube
TryNCode
Updated on June 04, 2022Comments
-
TryNCode almost 2 years
I'm using the SSH.NET library to connect to a remote SFTP server. I'm trying to use very basic code but it's not working
using (var client = new SftpClient(host, username, password)) { client.Connect(); client.ChangeDirectory(@"sftp://server.example.com/other_directory"); }
However, this throws an exception saying
No Such File
on theChangeDirectory
method.I tried the same with Curl but got an error saying
curl: (51) SSL peer certificate or SSH remote key was not OK
However, I added curl's --insecure argument and everything worked fine.
Could the
--insecure
part be related to why theSSH.NET
library isn't working or is there another reason? Is there a way to simulate what--insecure
does in C#?Thanks
-
Max Sorin about 8 yearsSounds to me like
sftp://server.example.com/
is denying you a secure connection. So it may be a configuration issue, and not anything you're doing wrong on the client side. -
TryNCode about 8 yearsI thought that may be the case at first but I'm able to access it via curl and other third party tools on my machine so I figured it would be on my side?
-
jdweng about 8 yearsCapture data using a sniffer like wireshark or fiddler and compare results between working and non working applications. Usually the issue is difference in the html header(s).
-
TryNCode about 8 years@jdweng Great idea, thanks!
-
TryNCode about 8 yearsFixed it, answer posted below
-
-
Martin Prikryl about 8 yearsThe
/other_directory
is an absolute path, not relative path. The point is the methods require paths, but you were giving URL instead. -
TryNCode almost 8 yearsI thought it's a relative path? It's relative to the working directory coffeecup.com/help/articles/absolute-vs-relative-pathslinks
-
Martin Prikryl almost 8 yearsThat article is wrong. It says "paths", but it's about URLs actually. We talk about paths here, not URLs. A path relative to working directory does cannot start with slash.