3

整个下午,

我对 .Net 的 SharpSSH 库有一个小问题(请参阅http://www.tamirgal.com/blog/page/SharpSSH.aspx

        SshStream ssh = new SshStream("some ip address", "some username", "some password");
        ssh.Prompt = "\n";
        ssh.RemoveTerminalEmulationCharacters = true;            

        ssh.Write("ssh some ip address");
        // Don't care about this response
        ssh.ReadResponse();

        ssh.Write("lss /mnt/sata[1-4]");
        // Don't care about this response (for now)
        ssh.ReadResponse();

        // while the stream can be read
        while (ssh.CanRead)
        {
            Console.WriteLine(ssh.ReadResponse());
        }

        ssh.Close();

如您所见,它相当简单。

但是,当进入while循环时,当所有内容都打印到控制台并且没有其他内容可读取时,它不会跳出循环。

无论如何,我可以在没有其他内容可读取的情况下手动强制它中断吗?

干杯,里克

4

2 回答 2

4

ssh.CanRead 表示 Stream 具有 Read 的实现,而不是可以读取。

于 2010-05-11T13:49:48.970 回答
0
while(true)                                                                            
{                                                                              
    //Write command to the SSH stream                                            
        ssh.Write( "some command or execute a script on aix" );                      
        data = "";                                                                   
        data = ssh.ReadResponse();                                                   
        if (data.Length < 10)     //don't wnat response like $                       
        continue;                                                                

        textWriter.Write(data);  //write all of data to file on each response loop   

        if (data.Contains("EOF"))    //was insert at end of file so I can terminate  
        break;                                                                      

}                                                                              
  textWriter.Close();                                                            
ssh.Close(); //Close the connection                                            
}                                                                                
于 2012-05-02T14:20:46.367 回答