Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# SFTP No Such File

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 the ChangeDirectory 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 the SSH.NET library isn't working or is there another reason? Is there a way to simulate what --insecure does in C#?

Thanks

like image 676
TryNCode Avatar asked Apr 01 '16 11:04

TryNCode


1 Answers

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

like image 193
TryNCode Avatar answered Sep 30 '22 00:09

TryNCode