Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

Thank you

like image 379
David Jiménez Martínez Avatar asked Mar 13 '23 11:03

David Jiménez Martínez


1 Answers

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");

like image 67
Martin Prikryl Avatar answered Mar 28 '23 19:03

Martin Prikryl