SocketTools .NET Edition

SshClient.Execute Method (String, Int32)

Execute a command on the server and return the output.

[Visual Basic]
Overloads Public Function Execute( _
   ByVal command As String, _
   ByVal timeout As Integer _
) As String
[C#]
public string Execute(
   string command,
   int timeout
);

Parameters

command
A string which specifies the command that will be executed on the server.
timeout
The number of seconds that the client will wait for a response before failing the operation.

Return Value

A string that contains the output of the command that was executed on the server. To get the exit code returned by the program, check the value of the ExitCode property. If an empty string is returned, this indicates that there was either no data available, or an error has occurred and the LastError property will return a non-zero value.

Remarks

The Execute method establishes a network connection with a remote server and executes the specified command. The output from the command is returned as a string. This method uses the following property values:

The value of the HostName or HostAddress property will be used to determine the server hostname or IP address.

The value of the RemotePort property will be used to determine the port number to connect to.

The value of the UserName and Password properties will be used to authenticate the session.

The value of the Options property will be used to specify the default options for the connection.

This method should not be used if the connection to the server must be established through a proxy server. If the connection must be made through a proxy server, then you should set the Command property to the specify the command to execute, call the Connect method to establish the connection, and then use either the Read or ReadLine methods to read the output.

When the command output is being read from the server, this method will automatically convert the data to match the end-of-line convention used on the Windows platform. This is useful when executing a command on a UNIX based system where the end-of-line is indicated by a single linefeed, while on Windows it is a carriage-return and linefeed pair. If the output contains embedded nulls or escape sequences, then this conversion will not be performed.

See Also

SshClient Class | SocketTools Namespace | SshClient.Execute Overload List