Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;鹦鹉问题:远程ssh服务器返回我自己的命令_C#_Ssh - Fatal编程技术网

C# &引用;鹦鹉问题:远程ssh服务器返回我自己的命令

C# &引用;鹦鹉问题:远程ssh服务器返回我自己的命令,c#,ssh,C#,Ssh,我的应用程序使用C#库与远程Ubuntu服务器连接。 有一段代码可以读取和写入客户机-服务器数据流: ShellStream mainStream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024);//it represents the main stream //send any data to sever StreamWriter writer = new StreamWriter(mainStream);//wrapp

我的应用程序使用C#库与远程Ubuntu服务器连接。
有一段代码可以读取和写入客户机-服务器数据流:

ShellStream mainStream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024);//it represents the main stream

//send any data to sever
StreamWriter writer = new StreamWriter(mainStream);//wrapper for main stream
await  writer.WriteLineAsync(command);
await  writer.FlushAsync();//flush data from main stream (i.e. send to server)

//get data from server (this is the timer's callback):
StreamReader reader = new StreamReader(mainStream);//another wrapper for reading
StringBuilder sb = new StringBuilder();
char[] buffer = new char[128];
int i = 0;
    while (!cts.IsCancellationRequested)
        {
        if ((i = await reader.ReadAsync(buffer, 0, buffer.Length))!= 0)
        {
        sb.Append(buffer, 0, i);                  
        }                   
}
return sb.ToString(); 
它工作得很好,但有时它会返回我输入的服务器命令。我可能认为我的问题隐藏在代码中,但调试窗口显示数据来自主流,即服务器

是否可能我发送的命令已返回?还是我的问题出在错误的代码中

编辑:我在服务器上调用了“history”命令,它返回所有以前发送的命令。问题发生后,服务器不会从客户端接收任何命令。无论连接设置如何,都不会出现任何错误。
可能是什么