Sample code for SSH shell

Mar 31, 2013 at 2:27 AM
Edited Mar 31, 2013 at 2:27 AM
Hello,

Could someone post here a sample code for open ssh shell connection + sample command to send command to console ? Becasue I can't find anything in source code.
Apr 2, 2013 at 2:41 PM
Edited Apr 2, 2013 at 2:44 PM
string command = <your command>;
using (var ssh = new SshClient(connectionInfo))
{
    ssh.Connect();
    string reply = String.Empty;

    try
    {
        using (var shellStream = ssh.CreateShellStream("dumb", 0, 0, 0, 0, BUFFERSIZE))
        {
            // Wait for promt for 10 seconds, if time expires, exception is thrown
            reply = shellStream.Expect(new Regex(@":.*>"), new TimeSpan(0, 0, 10));
            shellStream.WriteLine(command);

            // Wait for Read for 10 seconds, if time expires, exception is thrown
            string result = shellStream.ReadLine(new TimeSpan(0, 0, 10));
        }
    }
    catch
    {
        // Do something
    }
}