Search code examples
c#sshsftpopensshssh.net

SSH.NET - Message type 80 is not valid


I have the following piece of code that tries to connect to an SFTP Server built with OpenSSH (The server works because I've been able to successfully connect to this FTP via WinSCP client):

ConnectionInfo ConnNfo = new ConnectionInfo("127.0.0.1", 22, "usertest",
    new AuthenticationMethod[]{

        // Pasword based Authentication
        new PasswordAuthenticationMethod("usertest","usertest"),
    }
);

// Upload A File
using (var sftp = new SftpClient(ConnNfo))
{
    sftp.Connect();
    sftp.ChangeDirectory(@"/C:/IISFTP/");
    using (var uplfileStream = File.OpenRead(uploadfn))
    {
        sftp.UploadFile(uplfileStream, uploadfn, true);
    }
    sftp.Disconnect();
}

When calling the sftp.Connect() line, it raises the following Exception:

Message type 80 is not valid

Why is this happening? How can I connect to my SFTP server with SSH.NET?

Tried both the latest SSH.NET from source and the NuGet Package (v2013.4.7 at the time of writing)

OpenSSH (I did a ssh -v localhost):
OpenSSH_7.1p1 Microsoft_Win32_port_with_VS, OpenSSL 1.0.2d 9 Jul 2015

Thank you


Solution

  • The message 80 stands for SSH_MSG_GLOBAL_REQUEST.

    Modern versions of OpenSSH server use this generic message for various proprietary extensions of the SSH protocol.

    Most clients will/should silently ignore unrecognized messages. The SSH.NET does ignore the SSH_MSG_GLOBAL_REQUEST too, but it does not expect the message until an authentication completes.

    Unfortunately it seems that OpenSSH sends some of these (maybe the [email protected]) even before the authentication.

    The problem has been fixed in SSH.NET 2016.0.0-beta1. See Issue #8 and Commit a1f46d4.


    In older versions, go to the Session.cs and in the Session.Connect() method move the below line somewhat up, above the authentication code:

    RegisterMessage("SSH_MSG_GLOBAL_REQUEST");
    

    I'd put it, just below this line:

    RegisterMessage("SSH_MSG_USERAUTH_BANNER");