Skip to content

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

Closed

Description

@harsh288

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.

Activity

  1. biocoder-frodo commented on Sep 22, 2019

    @biocoder-frodo

    Is it breaking because it takes too long, or are you traversing into a folder where you do not have access permissions? Your server admin should be able to tell you what is causing the aborted connection or change the timeout limit.
    How long does it take for the server to produce the same list of files in an interactive SSH session (Putty?)

  2. csxcode commented on Jul 4, 2020

    @csxcode

    I have the same problem, could you solve it?

  3. ecocarlisle commented on Jul 13, 2020

    @ecocarlisle

    We have been experiencing the same issue. Any update would be great.

    Uncaught exception [Renci.SshNet.Common.SshConnectionException: An established connection was aborted by the server.]
    at Renci.SshNet.SubsystemSession.WaitOnHandle(WaitHandle waitHandle, Int32 millisecondsTimeout)
    at Renci.SshNet.Sftp.SftpSession.RequestRealPath(String path, Boolean nullOnError)
    at Renci.SshNet.Sftp.SftpSession.GetCanonicalPath(String path)
    at Renci.SshNet.SftpClient.InternalUploadFile(Stream input, String path, Flags flags, SftpUploadAsyncResult asyncResult, Action`1 uploadCallback)

  4. csxcode commented on Jul 21, 2020

    @csxcode

    Anyone?

  5. drieseng commented on Jul 21, 2020

    @drieseng
    Member

    @csxcode Can you consult the server logs to find out why the SSH server closed the connection?

  6. erhan0 commented on Aug 7, 2020

    @erhan0

    We have been experiencing the same issue on connect....is there an update to this?

  7. drieseng commented on Aug 7, 2020

    @drieseng
    Member

    @erhan0 if no one bothers to check server logs, or provide access to a system that allows me to reproduce the problems ... then no, no update from my end.

  8. biocoder-frodo commented on Aug 7, 2020

    @biocoder-frodo

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

  9. Carcinogen72 commented on Aug 8, 2020

    @Carcinogen72

    Hi there, here is a bit of auth.log, the last line seems to be the problem. If you would like access then send me your public key.

    Aug 9 11:21:10 crsserver sshd[20806]: Accepted publickey for clientdata from 192.168.2.111 port 57507 ssh2: RSA SHA256:-
    Aug 9 11:21:10 crsserver sshd[20806]: pam_unix(sshd:session): session opened for user clientdata by (uid=0)
    Aug 9 11:21:10 crsserver systemd-logind[786]: New session 61 of user clientdata.
    Aug 9 11:22:10 crsserver sshd[20806]: pam_unix(sshd:session): session closed for user clientdata
    Aug 9 11:22:10 crsserver systemd-logind[786]: Removed session 61.
    Aug 9 11:29:36 crsserver sshd[20929]: fatal: mm_answer_moduli: bad parameters: 2048 2048 1024

    I'm using the same key to ssh in through the terminal as I'm using in code.

    Anson

  10. drieseng commented on Aug 9, 2020

    @drieseng
    Member

    @Carcinogen72 Your issue appears to be unrelated to the issue. If you have a way to us to reproduce this issue (you can contact me privately to share connection info), please open a new issue.

  11. julianperrott commented on Jan 21, 2022

    @julianperrott

    This may not help you but it may help someone with a similar issue. We are using a 2016 version which is experiencing these errors:

    • An established connection was aborted by the server.
    • An existing connection was forcibly closed by the remote host

    This was caused by being blocked by Cisco Meraki Intrusion detection. The particular rules which were triggered were:

    • Buffer overflow in sshd in OpenSSH 2.3.1 through 3.3 may allow remote attackers to execute arbitrary code via a large number of responses during challenge response authentication when OpenBSD is using PAM modules with interactive keyboard authentication (PAMAuthenticationViaKbdInt).

    • Integer overflow in sshd in OpenSSH 2.9.9 through 3.3 allows remote attackers to execute arbitrary code during challenge response authentication (ChallengeResponseAuthentication) when OpenSSH is using SKEY or BSD_AUTH authentication.

  12. dchiranjib commented on Nov 24, 2022

    @dchiranjib

    Using the latest version (2021.10.2) and still getting the same error. Can't find any details on the server side too. I have failed on both an on-prem and a k8s environment. Can anyone shade some light? Thanks

  13. drieseng commented on Nov 24, 2022

    @drieseng
    Member

    @dchiranjib Do you happen to have a server (or specific docker image) that I can use to reproduce this issue against?

  14. dchiranjib commented on Nov 24, 2022

    @dchiranjib

    @drieseng unfortunately I can't share those details, but I can explain how I am trying to connect. I am using a host, port 22, username, password, a proxy host in the middle, port number of the proxy, and using Socks5 method.

    I tried with both ConnectionInfo with Password authentication and PasswordConnectionInfo, then tried with object of both SftpClient and SSHClient, but ended up with the same outcome, failing while calling Connect method.

    Uncaught exception [Renci.SshNet.Common.SshConnectionException: An established connection was aborted by the server.]

    Checked the IP's that my organization is exposing and they are already whitelisted by the sFTP server.

  15. RPJack commented on Jun 7, 2023

    @RPJack

    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

  16. WojciechNagorski commented on Dec 21, 2023

    @WojciechNagorski
    Collaborator

    It's done in #1274

  17. added this to the 2023.0.1 milestone on Dec 21, 2023
  18. WojciechNagorski commented on Dec 29, 2023

    @WojciechNagorski
    Collaborator

    The 2023.0.1 version has been released to Nuget: https://www.nuget.org/packages/SSH.NET/2023.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions