SshClient RunCommand Method SSH .NET Client Library Documentation
Creates and executes the command.

Namespace: Renci.SshNet
Assembly: Renci.SshNet (in Renci.SshNet.dll) Version: 0.1.0.0 (1.0.0.0)
Syntax

public SshCommand RunCommand(
	string commandText
)

Return Value

Returns an instance of SshCommand with execution results.
Exceptions

Remarks

This method internally uses asynchronous calls.
Examples

client.Connect();

var testValue = Guid.NewGuid().ToString();
var command = client.RunCommand(string.Format("echo {0}", testValue));
var result = command.Result;
result = result.Substring(0, result.Length - 1);    //  Remove \n character returned by command

client.Disconnect();
System.Threading.Tasks.Parallel.For(0, 10000,
    () =>
    {
        var client = new SshClient(host, username, password);
        client.Connect();
        return client;
    },
    (int counter, ParallelLoopState pls, SshClient client) =>
    {
        var result = client.RunCommand("echo 123");
        Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));
        return client;
    },
    (SshClient client) =>
    {
        client.Disconnect();
        client.Dispose();
    }
);
See Also