SSH.NET icon indicating copy to clipboard operation
SSH.NET copied to clipboard

Server identification problem in NETStandart 2.0

Open Kutikov opened this issue 8 years ago • 55 comments

Renci.SshNet.Common.SshConnectionException: "Server response does not contain SSH protocol identification." - VS 2017, causes only using UWP with NETStandart 2.0, but on UWP with NETCore there were no problems. After 2,5 hours of testing I`ve found out that problem is in timeouts of Session/ Could you fix it up?

Kutikov avatar Jan 21 '18 21:01 Kutikov

while waiting for a solution I use: https://github.com/asmodat/Asmodat-Standard-SSH.NET He corrected the problem.

doodz avatar Nov 15 '18 08:11 doodz

one single huge commit :\ wish it was better documented as to what the changes are

On Nov 15, 2018, at 4:13 AM, Doods [email protected] wrote:

while waiting for a solution I use: https://github.com/asmodat/Asmodat-Standard-SSH.NET https://github.com/asmodat/Asmodat-Standard-SSH.NET He corrected the problem.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/sshnet/SSH.NET/issues/377#issuecomment-438953973, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0HgP9guWLJ12lnYQtVgH6Rrp9aNnAks5uvSIdgaJpZM4Rl-Gv.

darkoperator avatar Nov 15 '18 13:11 darkoperator

For me, this is not the best alternative in the long run. As I said, waiting for the correction, it could help @ nick-goloborodko in the medium term.

doodz avatar Nov 15 '18 14:11 doodz

Do any of you have a server I can reproduce this issue again?

drieseng avatar Nov 15 '18 17:11 drieseng

@drieseng I sent you an email with my contact informations. I will be able to show you my configuration which is having this issue.

avboivin avatar Nov 15 '18 17:11 avboivin

After validating, it seems this issue is caused by the SFTP server actively refusing the connection using either a firewall rule or some sort of IP-based blocking.

This is not an issue caused by SSH.NET but rather by the connectivity to your SFTP server.

avboivin avatar Nov 15 '18 18:11 avboivin

@doodz @Kutikov @theescapers Can any of you consistently reproduce this issue, and provide me access to one of the (test) servers that show this issue?

drieseng avatar Nov 15 '18 21:11 drieseng

hello @drieseng sorry for the late. What you want say for server? I'm use a vm in local and use my personal computer for start ssh session with ssh.net. You want an access of my vm in ssh ?

doodz avatar Nov 20 '18 09:11 doodz

I am having this problem with Iot Core, but only when using the loop back address in my UWP app. I use the loop back to run system commands outside of the app sandbox.

NOTE: I've not done a complete code analysis, this is just what I came up with after stepping through the code a few times.

I believe that it has something to do with the loop back connection being much faster than than the remote connection, but I'm not certain.

E.g. If I step through the code, and get the point that is highlighted in the below image, I get an unhanded object disposed : Safe handle has been closed exception.

image

I'm not sure why it only does it when I step through the code, but I suspect that, since the SendCompleted callback is called by each async call to Send, the threads are stomping on each other, since there is no lock mechanism, hence the "object disposed exception."

image

Anyway, I notice that the cause of the error is that when verifying the server version, there are no bytes returned. However, if you modify theSocketAbstraction.Readmethod as such:

image

It returns the correct number of bytes read.

You would also need to modify all other instances of the "sendReceiveToken.TotalBytesTransferred" for determining the number of bytes read.

However, rather than modifying the code, which seems risky to me since I don't know what kind of regression that might cause, I chose to define the FEATURE_SOCKET_SYNC compiler define at the top of the SocketAbstraction.cs file. This made it work for me.

In my calling code I run a SSH command like this with a timeout:

image

lprofitt avatar Jan 10 '19 22:01 lprofitt

I'm also seeing Exception: Server response does not contain SSH protocol identification.: Renci.SshNet: at Renci.SshNet.Session.Connect() while running on AWS Lambda. It is inconsistent.

.NET version: Core 2.1 Language: C# Environment: Probably Amazon Linux.

The function tries to connect to the same server multiple times, each attempt with a different user/pass combination and performs some operations on dirs and files.

This is a snippet of the code that randomly raise this error:

private void ProcessDirectories(string process_path, ref SftpClient sftp)
{
     try
     {
         if (!sftp.IsConnected)
         {
            sftp.Connect(); // <-- It fails here
        }

        if (!Directory.Exists(process_path + "/processed"))
        {
           Directory.CreateDirectory(process_path + "/processed");
        }

        DirectoryInfo directory = new DirectoryInfo(process_path);
        ... // More data processing
    }
}

maybe there's an issue with passing the SftpClient object as a reference?

estebanz01 avatar Jan 22 '19 14:01 estebanz01

We are also seeing this with .NET Core 2.2 and C# in Azure. It is fairly consistent; it happens with some servers and not with others. Unfortunately only in production, so I can't provide a test server. I will be happy to help testing a fix though.

@lprofitt did you create a fork? Ideally I'd like to change the calling code that I control rather than code in the library itself unless the official library can be fixed.

erik-wramner avatar Aug 19 '19 09:08 erik-wramner

@erik-wramner, I did not create a fork, I just modified my local copy.

lprofitt avatar Aug 19 '19 16:08 lprofitt

Any updates on solving this?

M1XGear avatar Sep 18 '19 12:09 M1XGear

I'm receiving this issue as well. any updates/ quick fixes?

Ashetyn avatar Nov 01 '19 13:11 Ashetyn

@M1XGear and @Ashetyn, Pull the whole project down, and define the FEATURE_SOCKET_SYNC compiler define at the top of the SocketAbstraction.cs file and, it to your solution, and reference that rather than using nuget.

lprofitt avatar Nov 01 '19 21:11 lprofitt

I'm also seeing this Exception a few times a day in our production environment: Renci.SshNet.Common.SshConnectionException: Server response does not contain SSH protocol identification. at Renci.SshNet.Session.Connect() at Renci.SshNet.BaseClient.Connect()

SSH.NET version: NuGet 2016.1.0.0 .NET version: .NET framework 4.7.2 Environment: Windows Server 2019 Language: C#

EddyRts avatar Feb 07 '20 12:02 EddyRts

Also experiencing that issue on our side

natalie-o-perret avatar Feb 27 '20 09:02 natalie-o-perret

Working fine locally in windows 10 but throwing exception in azure function app.

KhalilMohammad avatar Mar 22 '20 00:03 KhalilMohammad

I had the same issues. I started to try using other solutions on NUGET. Actually a Fork from Renci/SSH.NET solved this problem if anyone still is having issues. https://www.nuget.org/packages/SSH.NET.Fork/2018.8.25.2?_src=template With that Package my SSH Connection works just fine with UWP/Xamarin etc..

zerathun avatar Mar 24 '20 14:03 zerathun

I've identified a bug in our EAP socket implementation that surfaces when an async operation completes synchronously.

drieseng avatar Mar 28 '20 18:03 drieseng