SshCommand Execute Method SSH .NET Client Library Documentation
Executes command specified by CommandText property.

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

public string Execute()

Return Value

Command execution result
Exceptions

Examples

client.Connect();

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

client.Disconnect();
client.Connect();

var cmd = client.CreateCommand(";");
cmd.Execute();
if (!string.IsNullOrEmpty(cmd.Error))
{
    Console.WriteLine(cmd.Error);
}

client.Disconnect();
client.Connect();
var cmd = client.CreateCommand("sleep 10s");
cmd.CommandTimeout = TimeSpan.FromSeconds(5);
cmd.Execute();
client.Disconnect();
See Also