sshnet / SSH.NET

SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
http://sshnet.github.io/SSH.NET/
MIT License
4.01k stars 932 forks source link

System.Net.Sockets.SocketException: 'An existing connection was forcibly closed by the remote host.' #1002

Open Bradenb25 opened 2 years ago

Bradenb25 commented 2 years ago

I'm able to initially connect to the sftp server. However, after the initial file upload I try and reconnect to upload another file. This is when I get 'An existing connection was forcibly closed by the remote host.' The connection and upload process I'm using is very simple.

image

It seems like when I disconnect it's not fully disconnecting so when trying to reconnect it throws this exception.

mittapalliseshu commented 2 years ago

Did you get a fix for this? even I am facing the same issue now.

duncan-bradley commented 2 years ago

Update: You have to create a host key on AWS that matches the type of key you are using for the private key....by default, the host key type used in AWS is not supported by this library.

I am getting the same issue connection to an AWS hosted SFTP server using v2020.0.2. The extact error from the AWS logs is : ERRORS KEX_FAILURE Message="no matching host key type found" Kex=ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,ssh-dss SourceIP=... I am using a ssh-rsa keyfile to authenticate, but this error suggests that AWS is not liking the host keyfile algorithm that is being sent. I tried to interrogate the type on the connectionInfo class using connectionInfo.CurrentHostKeyAlgorithm, but this returns null as it is not connected at that point. Any ideas any one?

revealer409 commented 6 days ago

Solution: In my case I was using SSH.NET library from some xyz vendor removed package from Nugget package manager and then installed SSH.NET by Renci fixed my issue.

issue background: due to some issue infra team has deleted FTP/*/Log directory from Server after that i was getting this issue 'An existing connection was forcibly closed by the remote host'