无法从'System.IO.TextWriter'转换为'System.IO.Stream'

ahm*_*lim 0 c#

        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();
Run Code Online (Sandbox Code Playgroud)

这行错误:

var shell = ssh.CreateShell(input, Console.Out, Console.Out, "xterm", 80, 24, 800, 600, "");
Run Code Online (Sandbox Code Playgroud)

错误:错误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

任何解决方案

Joh*_*ick 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();
Run Code Online (Sandbox Code Playgroud)

虽然注意两次传递它似乎是错误的.您可能希望为第二个或第三个参数传递其他内容ssh.CreateShell.可能Console.OpenStandardInput()就此而言.