C# SSH.NET CreateCommand/RunCommand does not work

别说谁变了你拦得住时间么 提交于 2020-07-19 08:46:42

问题


I would like to create an application to send SSH commands to HP Switches and some other devices. But from HP Switch I get response "SSH command execution is not supported.".

I use this part of a code.

SshClient sshclient = new SshClient(IP,username, pass);
sshclient.Connect();
SshCommand sc = sshclient.CreateCommand("conf");
sc.Execute();
string answer = sc.Result;
label9.Text = answer;

Any ideas how to make the interactive shell emulation? I found only this thread regarding to this issue. phpseclib - attempting to connect to an HP procurve switch returns error: SSH command execution is not supported


回答1:


Your code is correct in general. But it seems, that the particular device does not support the SSH "exec" channel, what is behind the SshCommand class.

As the answer to the question you have linked yourself suggests, you have to unfortunately emulate a shell by using SSH "shell" channel.

For that use SshClient.CreateShell and write the command to its input stream.

Note that this is just a workaround for your specific situation. In general, the "shell" channel shall not be used for automation.



来源:https://stackoverflow.com/questions/45227308/c-sharp-ssh-net-createcommand-runcommand-does-not-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!