Skip to content

Executing different commands using same object throwing Renci.SshNet.Common.SshConnectionException: An established connection was aborted by the server. #213

Closed

Description

@vvvarunv
    public void Test_Execute_Command_Same_Object_Different_Commands()
    {
        using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
        {
            client.Connect();
            var cmd = client.CreateCommand("sh ver");
            cmd.Execute();
            //Assert.AreEqual("12345\n", cmd.Result);
            cmd.Execute();    ---> Failing here 
            //Assert.AreEqual("23456\n", cmd.Result);
            client.Disconnect();
        }

}

internal void SendMessage(Message message)
{
if (!_socket.CanWrite())
throw new SshConnectionException("Client not connected."); --> Throws exception here

Activity

  1. vvvarunv commented on Apr 23, 2017

    @vvvarunv
    Author

    Seems similar to this - https://sshnet.codeplex.com/workitem/563

    But it is throwing exception for me

  2. kasbst commented on Apr 27, 2017

    @kasbst

    @vvvarunv I'm not able to reproduce your issue connecting against Ubuntu 14.04.5 LTS using SSH.NET 2016.0.0 and 2016.1.0-beta1.

    using (var client = new SshClient(server, username, password))
     {
             client.Connect();
    
             var cmd = client.CreateCommand("hostname");
             cmd.Execute();
             Console.WriteLine("Command 1: " + cmd.Result);
    
             cmd.Execute("pwd");
             Console.WriteLine("Command 2: " + cmd.Result);
    
             client.Disconnect();
     }

    Could you please share your configuration details (I assume you are trying to execute commands on Cisco IOS device) or preferably you might want to use ShellStream to execute several different commands.

  3. darkoperator commented on Apr 27, 2017

    @darkoperator
  4. kasbst commented on Apr 27, 2017

    @kasbst

    Yep, just wanted to be sure as it was already mentioned in this issue #52 :)

  5. vvvarunv commented on May 8, 2017

    @vvvarunv
    Author

    @darkoperator : you are correct, i am running this command against a cisco device. I was able to use shellstream and get past this issue.

  6. sasha-amadiro commented on Feb 11, 2018

    @sasha-amadiro

    this.shellStreamSSH.Write("\u0003");
    it works
    http://joxi.ru/brRz8g5HQZDOPr.png

  7. WojciechNagorski commented on Dec 21, 2023

    @WojciechNagorski
    Collaborator

    It's done in #1274

  8. added this to the 2023.0.1 milestone on Dec 21, 2023
  9. 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

  10. pray4snow2 commented on Feb 6, 2024

    @pray4snow2

    2023.0.1 did NOT fix this issue for me on a Cisco device.

  11. WojciechNagorski commented on Feb 6, 2024

    @WojciechNagorski
    Collaborator

    @pray4snow2 you should provide more logs and more information about your environment and device. Do you get an exception? Without this, no one will help you unless you prepare a PR with a solution yourself.

  12. pray4snow2 commented on Feb 7, 2024

    @pray4snow2

    This issue happens when trying to connect to the end device (Cisco IOS) multiple times, and never happens on the first attempt.

    Output shows:

    Exception thrown: 'Renci.SshNet.Common.SshConnectionException' in Renci.SshNet.dll
    An established connection was aborted by the server.

    and the exception thrown:

    Renci.SshNet.Common.SshConnectionException
    HResult=0x80131500
    Message=An established connection was aborted by the server.
    Source=Renci.SshNet
    StackTrace:
    at Renci.SshNet.SshCommand.WaitOnHandle(WaitHandle waitHandle)
    at Renci.SshNet.SshCommand.EndExecute(IAsyncResult asyncResult)
    at Renci.SshNet.SshClient.RunCommand(String commandText)
    at Application.Form1.GetData() in C:\Users\me\Documents\Visual Studio 2022\Projects\Application\Form1.vb:line 376

    End device logging shows nothing important with a good or bad result, no difference:

    *Feb 7 04:32:28.520: %SEC_LOGIN-5-LOGIN_SUCCESS: Login Success [user: admin] [Source: 192.168.1.100] [localport: 22] at 04:32:28 EST Wed Feb 7 2024

    *Feb 7 04:32:28.640: %SSH-5-SSH_COMPLIANCE_VIOLATION_RSA_KEY_SIZE: SSH RSA Key Size compliance violation detected. Kindly note that the usage of keys smaller than 2048 bits will be deprecated in the upcoming releases. Please revise your key configuration accordingly to avoid service impact.

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