You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Executing different commands using same object throwing Renci.SshNet.Common.SshConnectionException: An established connection was aborted by the server. #213
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
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.
I believe he is running the command against a Cisco device, it is a known problem with some embedded devices that they do not support well exec call, if it is a Cisco divice you will have to use a stream, this way a terminal is created and you can execute commands by writing to it and read the output by reading from the stream directly.
On Apr 27, 2017, at 8:20 AM, kasbst ***@***.***> wrote:
@vvvarunv <https://github.com/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();
}
Preferably you might want to use ShellStream to execute several different commands.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#213 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAf0HheWIx5uh6y2ZHveHM30EujLhHvXks5r0IgZgaJpZM4NFTpn>.
@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.
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.
Activity
vvvarunv commentedon Apr 23, 2017
Seems similar to this - https://sshnet.codeplex.com/workitem/563
But it is throwing exception for me
kasbst commentedon 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.
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 commentedon Apr 27, 2017
kasbst commentedon Apr 27, 2017
Yep, just wanted to be sure as it was already mentioned in this issue #52 :)
vvvarunv commentedon 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.
sasha-amadiro commentedon Feb 11, 2018
this.shellStreamSSH.Write("\u0003");
it works
http://joxi.ru/brRz8g5HQZDOPr.png
WojciechNagorski commentedon Dec 21, 2023
It's done in #1274
WojciechNagorski commentedon Dec 29, 2023
The 2023.0.1 version has been released to Nuget: https://www.nuget.org/packages/SSH.NET/2023.0.1
pray4snow2 commentedon Feb 6, 2024
2023.0.1 did NOT fix this issue for me on a Cisco device.
WojciechNagorski commentedon Feb 6, 2024
@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 commentedon 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.