var ssh = new SshClient("ip", "user", "pass");
var input = new MemoryStream(Encoding.ASCII.GetBytes("exit\r\n"));
var shell = ssh.CreateShell(input, Console.Out, Console.Out, "xterm", 80, 24, 800, 600, "");
shell.Stopped += delegate(object sender, EventArgs e)
{
Console.WriteLine("\nDisconnected...");
};
shell.Start();
Thread.Sleep(1000 * 1000);
shell.Stop();
错误就在这一行:
var shell = ssh.CreateShell(input, Console.Out, Console.Out, "xterm", 80, 24, 800, 600, "");
错误: 错误3参数2:无法从'System.IO.TextWriter'转换为'System.IO.Stream'D:\ applications area \ test \ ConsoleApplication1 \ ConsoleApplication1 \ Program.cs 19 48 ConsoleApplication1
错误4参数3:无法从'System.IO.TextWriter'转换为'System.IO.Stream'D:\ applications area \ test \ ConsoleApplication1 \ ConsoleApplication1 \ Program.cs 19 61 ConsoleApplication1
任何解决方案?
答案 0 :(得分:5)
Console.Out
是TextWriter
,而非流。
尝试这样的事情(警告:编译成头)
Stream stdout = Console.OpenStandardOutput();
var ssh = new SshClient("ip", "user", "pass");
var input = new MemoryStream(Encoding.ASCII.GetBytes("exit\r\n"));
var shell = ssh.CreateShell(input, stdout, stdout, "xterm", 80, 24, 800, 600, "");
shell.Stopped += delegate(object sender, EventArgs e)
{
Console.WriteLine("\nDisconnected...");
};
shell.Start();
Thread.Sleep(1000 * 1000);
shell.Stop();
虽然注意两次传递似乎是错误的。您可能希望将第二个或第三个参数传递给ssh.CreateShell
。可能Console.OpenStandardInput()
,就此而言。