Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: Sample code for SSH shell

$
0
0
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
    }
}

Viewing all articles
Browse latest Browse all 1729

Trending Articles