0

我正在使用 ssh.net ssh 到外部盒子,在运行任何命令后,无论我写什么命令,我总是得到“无效命令\n”,连接没有错误,我可以在 Client.IsConnected = true 中看到并且如果错误的密码连接无效并且程序失败。问题是命令总是从 Command.Result = "Invalid command\n" 框中得到相同的回复。如果我通过 putty 登录,我可以毫无问题地运行“帮助”命令。另一个有趣的事实是 linux 命令 w 显示连接了哪些用户,所以如果我通过 putty 登录,我可以看到 user1,但是对于这个小程序,这不会发生

命名空间 SSHconsole { 类 MainClass {

    public static void Main(string[] args)
    {
        //Connection information
        string user = "user1";
        string pass = "pass1";
        string host = "X.X.X.X";

        var connectionInfo = new PasswordConnectionInfo(host, user, pass);

        //Set up the SSH connection
        using (var client = new SshClient(connectionInfo))
        {

            connectionInfo.AuthenticationBanner += delegate (object sender, AuthenticationBannerEventArgs e)
            {
                Console.WriteLine(e.BannerMessage);
            };
            //Start the connection
            client.Connect();
            var command = client.RunCommand("help");
            Console.WriteLine(command.Result);
            client.Disconnect();
        }

    }
}

}

4

0 回答 0