SocketTools .NET Edition

SshClient.Execute Method (String, Int32, String, String, String)

Execute a command on the server and return the output.

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

Parameters

hostName
A string which specifies the remote host to establish a connection with. This may specify a host name or an Internet address in dot-notation.
hostPort
An integer which specifies the port number for the connection. This value must be greater than zero and the maximum valid port number is 65535.
userName
A string which specifies the user name which will be used to authenticate the client session.
password
A string which specifies the password which will be used to authenticate the client session.
command
A string which specifies the command that will be executed on the server.

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 Timeout property will be used to specify the timeout period.

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