Executes command specified by CommandText property.
Namespace: Renci.SshNetAssembly: Renci.SshNet (in Renci.SshNet.dll) Version: 0.1.0.0 (1.0.0.0)
Syntax
Return Value
Command execution resultExceptions
| Exception | Condition |
|---|---|
| Renci.SshNet.Common SshConnectionException | Client is not connected. |
| Renci.SshNet.Common SshOperationTimeoutException | Operation has timed out. |
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