Server identification problem in NETStandart 2.0
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?
while waiting for a solution I use: https://github.com/asmodat/Asmodat-Standard-SSH.NET He corrected the problem.
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.
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.
Do any of you have a server I can reproduce this issue again?
@drieseng I sent you an email with my contact informations. I will be able to show you my configuration which is having this issue.
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.
@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?
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 ?
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.

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."

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:

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:

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?
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, I did not create a fork, I just modified my local copy.
Any updates on solving this?
I'm receiving this issue as well. any updates/ quick fixes?
@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.
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#
Also experiencing that issue on our side
Working fine locally in windows 10 but throwing exception in azure function app.
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..
I've identified a bug in our EAP socket implementation that surfaces when an async operation completes synchronously.