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 は、ストリームが読み取り可能であることではなく、読み取り用の実装を持っていることを示します。

于 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 に答える