我似乎不能让这个图书馆工作。我正在做一些很简单的事情,但我还是做不到。
client.Connect();
client.RunCommand("sudo passwd test");
Thread.Sleep(1000);
client.RunCommand("testtest");
Thread.Sleep(1000);
client.RunCommand("12345");
Thread.Sleep(1000);
client.RunCommand("12345");
bool primera = true;
client.Disconnect();如果我尝试使用刚才发布的凭据登录测试,它就失败了。但是,如果我通过我的终端通过普通SSH执行相同的命令,我就可以登录。为什么SSH.NET不执行这些命令?
发布于 2014-03-17 03:31:43
问题在于,在运行client.RunCommand("sudo passwd test");之后,程序正在运行,等待输入。直到程序返回之后,RunCommand方法才会实际运行该命令。
我在尝试运行su - <login>时遇到了同样的问题,并找到了以下解决方法.
Shell = Client.CreateShellStream("xterm", 80, 24, 800, 600, 1024);
Reader = new StreamReader(Shell);
Writer = new StreamWriter(Shell);
Writer.AutoFlush = true;
Writer.Write("su - " + login2 + "\n");
while (true)
{
var output = Reader.ReadLine();
if (output.EndsWith("Password: "))
{
break;
}
}
Writer.Write(password2 + "\n");https://stackoverflow.com/questions/22445316
复制相似问题