简体   繁体   English

通过 ssh.net 向 aruba 交换机或虚拟 controller 发送命令时无法获取 output

[英]Unable to get output when sending commands via ssh.net to aruba switch or virtual controller

I am attempting to remote into a virtual controller to run aruba commands into the console such as "show run" etc but no output is coming up for the commands.我正在尝试远程进入虚拟 controller 以在控制台中运行 aruba 命令,例如“显示运行”等,但没有 output 出现命令。 It appears I am able to successfully connect, and I am not seeing any errors, but nothing happens when running a command.看来我能够成功连接,并且没有看到任何错误,但是运行命令时没有任何反应。

I have connected via putty to validate the commands, and also validate credentials.我已通过 putty 连接以验证命令,并验证凭据。 I have been able to do similar functionality via python, but am needing to be able to do this via C# for dependency reasons.我已经能够通过 python 执行类似的功能,但由于依赖原因,我需要能够通过 C# 执行此操作。

                var methods = new List<AuthenticationMethod>();
                methods.Add(new PasswordAuthenticationMethod(UserName, Password));
                var con = new ConnectionInfo(virtualController, 22, UserName, methods.ToArray());

                Console.WriteLine("Attempting Connection with Network...");
                var Client = new SshClient(con);
                Client.Connect();
                Console.WriteLine("Successfully Connected.");

                var cmdRun = Client.RunCommand(showClients);
                var result = cmdRun.Result;
                Console.WriteLine(result);

                cmdRun = Client.RunCommand(showRun);
                result = cmdRun.Result;
                Console.WriteLine(result);

                Client.Disconnect();

The console outputs "Successfully Connected."控制台输出“成功连接”。 and continues to execute all code, but never outputs anything on the line:并继续执行所有代码,但从不输出任何内容:

Console.WriteLine(result); Console.WriteLine(结果);

I would expect for the terminals output that I would see when running this command via putty.我希望通过 putty 运行此命令时会看到终端 output。

I use SSHClient instead of Client .我使用SSHClient而不是Client Using my class from this answer , here's some sample code after calling Client.Connect() :这个答案中使用我的 class ,这是调用Client.Connect()后的一些示例代码:

SSHStream = SSHClient.CreateExtShellStream("dumb", 120, 80, 0, 0, 65536);
if (SSHStream != null) {
    DoCommand("no page");
    Connected = true;
}

var result = DoCommand("show cdp neighbors | begin Port", TimeSpan.FromSeconds(2), "#");

Here is the helper method:这是辅助方法:

public static IEnumerable<string> DoCommand(string c, TimeSpan? timeout = null, string prompt = "#") {
    return SSHStream.DoCommand(c, timeout ?? TimeSpan.FromSeconds(2), prompt);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM