Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

dargento

Re: I get Error "Connection has been unexpectedly closed. Server sent command exit status 2"

Yes after changing the protocol to SCP, it is working now. Thank you so much!!!
martin

Re: I get Error "Connection has been unexpectedly closed. Server sent command exit status 2"

In GUI, you are using SCP protocol (while you might have selected SFTP, the GUI falls back to SCP automatically, if SFTP does not work).

Your SFTP server is broken:
! /bin/sh: exec: line 3: sftp-server: not found

Get the SFTP server fixed. Or use Protocol.Scp in the code.
dargento

Re: I get Error "Connection has been unexpectedly closed. Server sent command exit status 2"

I have packed the two logs into one file in the att. Thanks in advance :)
dargento

I get Error "Connection has been unexpectedly closed. Server sent command exit status 2"

Hello
It is the first time I programmed the WinSCP client in .NET. We have hundreds of Siemens 840D sl CNC controllers where the OS is Linux. We want to read some files of these controllers from our Windows server where our C# app is running. I have used your sample code.

One info in advance!
We can connect to all the machines with the WinSCP GUI without any problem. We are just getting a warning message like "The first key-exchange algorithm supported by the server is diffie-hellman-group1-sha1, which is below the warning treshold. Do you want to continue with the connection?" If we sey yes then connection is established.


  • First I tried without any security
    SessionOptions sessionOptions = new SessionOptions
    {
        Protocol = Protocol.Sftp,                   
        HostName = "10.92.XXX.XXX",
        UserName = "user",
        Password = "XXXXX",
        PortNumber = 22,
        GiveUpSecurityAndAcceptAnySshHostKey = true,                   
    };

    I got the Error:
    The key-exchange algorithm diffie-hellman-group1-sha1 was not verified!

  • I added fingerprint as following. (I didn't know what the fingerprint was. I connected with the WinSCP GUI to the same machine and took the fingerprint from the function "Generate Transfer Code"
        //GiveUpSecurityAndAcceptAnySshHostKey=true,  
        SshHostKeyFingerprint = "ssh-dss 1024 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=",

    I got again the Error: The key-exchange algorithm diffie-hellman-group1-sha1 was not verified!
  • I finally tried to add following KEX setting
    sessionOptions.AddRawSettings("KEX", "ecdh,dh-gex-sha1,dh-group14-sha1,rsa,dh-group1-sha1,WARN");

    The the Error changed to "Connection has been unexpectedly closed. Server sent command exit status 2". I am totally confused. How should I proceed?

Finally we need a solution where we can connect to all the machines without entering any fingerprints just like the WinSCP GUI. I mean with the WinSCP GUI its possible without doing any additional setting on the GUI (With default settings). Why isn't working with the .NET code?