HelPHP

Ssh
in package

Tags
class

Ssh

Provides SSH communication capabilities, including command execution and optional tunneling. Supports authentication via username/password or public/private key files. Can establish a direct SSH connection or tunnel through an intermediate host.

Can permit communication between a docker container to a hosting server as tunnel for a container running on it !

Table of Contents

Properties

$command  : string
$host  : string
$password  : string
$port  : int
$privatekeyfile  : string
$pubkeyfile  : string
$result  : mixed
$tunneltarget  : string|false
$tunnelwithkey  : bool
$username  : string
$withkey  : bool

Methods

__construct()  : mixed
Ssh constructor.
send()  : string
Establishes the SSH connection, authenticates, and executes the command.

Properties

$command

public string $command

The command to execute on the remote host.

$host

public string $host

Destination host.

$password

public string $password

SSH password (if using password authentication).

$port

public int $port

Destination port.

$privatekeyfile

public string $privatekeyfile

Path to the private key file (if using key authentication).

$pubkeyfile

public string $pubkeyfile

Path to the public key file (if using key authentication).

$result

public mixed $result

The result of the executed command.

$tunneltarget

public string|false $tunneltarget

Optional. Tunnel target in the same format as destination.

$tunnelwithkey

public bool $tunnelwithkey

Whether to use key authentication for the tunnel.

$username

public string $username

SSH username.

$withkey

public bool $withkey

Whether to use key authentication.

Methods

__construct()

Ssh constructor.

public __construct(string $destination, string $command[, string|false $tunneltarget = false ]) : mixed

Parses the destination string, sets up authentication parameters, and executes the command. Supports both direct SSH and SSH tunneling.

Parameters
$destination : string

Connection string in the format user:pass@host:port or if with keys: username:path_to_pub_file/pub_file_name:path_to_priv_file/priv_file_name@host:port.

$command : string

The command to execute on the remote host.

$tunneltarget : string|false = false

Optional. Tunnel target in the same format as destination.

send()

Establishes the SSH connection, authenticates, and executes the command.

public send() : string

Handles both direct and tunneled connections, and supports password or key authentication.

Return values
string —

The output of the executed command, or an error message on failure.


        
On this page

Search results