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

Advertisement

dargento
Joined:
Posts:
3

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?

Reply with quote E-mail

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,454
Location:
Prague, Czechia

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

Please post session log file for your third attempt with AddRawSettings, as well as WinSCP GUI session log.

Regarding your question about hostkey/fingerprint: I believe I've answered you already on Stack Overflow:
Why do I need to use SshHostKeyFingerprint in WinSCP .NET assembly, when WinSCP GUI does not require such option?

Reply with quote

dargento
Joined:
Posts:
3

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 :)
Description: I have packed the two logs into one file in the att

Reply with quote E-mail

martin
Site Admin
martin avatar
Joined:
Posts:
41,454
Location:
Prague, Czechia

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.

Reply with quote

Advertisement

You can post new topics in this forum