C# SFTP No Such File

11,139

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

Share:
11,139

Related videos on Youtube

TryNCode
Author by

TryNCode

Updated on June 04, 2022

Comments

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

    • Max Sorin
      Max Sorin about 8 years
      Sounds 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
      TryNCode about 8 years
      I 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
      jdweng about 8 years
      Capture 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
      TryNCode about 8 years
      @jdweng Great idea, thanks!
    • TryNCode
      TryNCode about 8 years
      Fixed it, answer posted below
  • Martin Prikryl
    Martin Prikryl about 8 years
    The /other_directory is an absolute path, not relative path. The point is the methods require paths, but you were giving URL instead.
  • TryNCode
    TryNCode almost 8 years
    I thought it's a relative path? It's relative to the working directory coffeecup.com/help/articles/absolute-vs-relative-pathslinks
  • Martin Prikryl
    Martin Prikryl almost 8 years
    That 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.