我正在尝试在 C# 中创建一个简单的 SSH 客户端。这是我现在的代码:
using Renci.SshNet;
public static void Main(string[] args)
{
AuthenticationMethod method = new PasswordAuthenticationMethod("pi", "raspberry");
ConnectionInfo connection = new ConnectionInfo("192.168.91.134", "pi", method);
SshClient client = new SshClient(connection);
if (!client.IsConnected)
{
Console.WriteLine("Not Connected...");
client.Connect();
}
while (true)
{
string command = Console.ReadLine();
SshCommand response = client.RunCommand(command);
Console.WriteLine(response.Result);
}
}
问题:
sudo su command
给个密码就不行了。。。(将来我想将输出添加到列表框并从 winForms 应用程序中的 texbox 获取输入)
预先感谢您的帮助
最佳答案
在你想实现一个 SSH 终端客户端(如 PuTTY)时,你需要使用 SSH“shell” channel 。
在 SSH.NET 中,使用 SshClient.CreateShell
或 SshClient.CreateShellStream
,而不是 SshClient.RunCommand
.
关于c# - 在 C# 中显示完整的 SSH shell 输出,包括登录消息和提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61158899/