Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vvvarunv opened this issue Apr 23, 2017 · 11 comments
Milestone

Comments

@vvvarunv
Copy link

    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

@vvvarunv
Copy link
Author

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

But it is throwing exception for me

@kasbst
Copy link

kasbst commented Apr 27, 2017

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

@darkoperator
Copy link

darkoperator commented Apr 27, 2017 via email

@kasbst
Copy link

kasbst commented Apr 27, 2017

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

@vvvarunv
Copy link
Author

vvvarunv commented May 8, 2017

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

@evka89
Copy link

evka89 commented Feb 11, 2018

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

@WojciechNagorski
Copy link
Collaborator

It's done in #1274

@WojciechNagorski WojciechNagorski added this to the 2023.0.1 milestone Dec 21, 2023
@WojciechNagorski
Copy link
Collaborator

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

@pray4snow2
Copy link

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

@WojciechNagorski
Copy link
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.

@pray4snow2
Copy link

pray4snow2 commented Feb 7, 2024

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants