Renci.SshNet.Common.SshConnectionException: An established connection was aborted by the server

See original GitHub issue

I 'm using Rencii package and it used to work however when I do List Directory which has got more than 2000 files, that is where it’s breaking and giving established connection was aborted.

using System;
using System.Collections.Generic;
using System.IO;
using Renci.SshNet;
namespace worship_sync
{
class Program
{
static void Main(string[] args)
{
const string host = "******";
const string username = "****";
const string password = "vagrant";
const string workingdirectory = "*****";
const string uploadfile = #"******";
Console.WriteLine("Creating client and connecting");
using (SftpClient client = new SftpClient(host, 8822, username, password))
{
client.Connect();
Console.WriteLine("Connected to {0}", host);
client.ChangeDirectory(workingdirectory);
Console.WriteLine("Changed directory to {0}", workingdirectory);
var listDirectory = client.ListDirectory(workingdirectory); // ERROR
Console.WriteLine("Listing directory:");
foreach (var fi in listDirectory)
{
Console.WriteLine(" - " + fi.Name);
}   
}
}
}
}

AND I got this error when I am runing my code: Unhandled Exception: Renci.SshNet.Common.SshConnectionException: An established connection was aborted by the server.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
biocoder-frodocommented, Aug 7, 2020

To the people asking for updates, have you tried running your code in Visual Studio in Debug mode? You should see plenty SshNet.Logging debug messages in the Output pane (Show output from: Debug) if you have a debug build of the library attached to your solution. Please see here https://github.com/sshnet/SSH.NET/wiki/Troubleshooting-SSH.NET e.g.

‘SynoDuplicateFolders.exe’ (CLR v4.0.30319: SynoDuplicateFolders.exe): Loaded ‘D:\github\SynoDuplicateFolders\SynoDuplicateFolders\bin\Debug\Renci.SshNet.dll’. Symbols loaded. Exception thrown: ‘Renci.SshNet.Common.SshPassPhraseNullOrEmptyException’ in Renci.SshNet.dll SshNet.Logging Verbose: 3 : Initiating connection to ‘diskstation:22’. SshNet.Logging Verbose: 3 : Server version ‘2.0’ on ‘OpenSSH_7.4’. SshNet.Logging Verbose: 4 : [] Received message ‘KeyExchangeInitMessage’ from server: ‘SSH_MSG_KEXINIT’.

0reactions
RPJackcommented, Jun 7, 2023

Hi everyone, i just encountered the same problem in my case, there are a few code and the logs are as follows:

authMethods.Add(new PasswordAuthenticationMethod(userName, password));
var connInfo = new ConnectionInfo(host, Convert.ToInt32(port), userName, authMethods.ToArray());
using (var sftpClient = new SftpClient(connInfo))
              {
                  sftpClient.Connect();
                  await SFTPDownload(sftpClient);
              }

client error log: Renci.SshNet.Common.SshConnectionException: An established connection was aborted by the server.\n at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)\n at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle)\n at Renci.SshNet.Session.Connect()\n at Renci.SshNet.BaseClient.CreateAndConnectSession()\n at Renci.SshNet.BaseClient.Connect()

server error log: 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=xxx.xxx.xxx.xxx

By the way, i used the same information connect success by openssh-client, but it can’t be correct result by my code which using Renci.SshNet. @drieseng Can you help me to check the Renci.SshNet’s ssh version different openssh-client image

Read more comments on GitHub >

github_iconTop Results From Across the Web

SSH.NET - An established connection was aborted by the ...
Today I've upgraded it to SLES12 SP1 and when I'm trying to connect with server (through application with SSH.NET) I get exception -...
Read more >
an established connection was aborted by the server
Hi All, We are facing issue while running the unix command. Running as simple command as "ls" is returning "an established connection was...
Read more >
An established connection was aborted by the server
Looking at this third-party open-source SSH library, the “aborted by the server” usually means a send or receive transferred zero bytes of data ......
Read more >
How to fix an established connection was aborted by the ...
Hello Team, While we are trying to connect SFTP using SSH public key authentication we are getting following error. Established connection ...
Read more >
Karaf server SSH connection not happing via ssh.net dll
Renci.SshNet.Common.SshConnectionException: An established connection was aborted by the server. However sshconnection to Karaf server-4.3.1 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found