wppaste
WordPress

WP_Filesystem_SSH2

Since
2.7.0
Source
wp-admin/includes/class-wp-filesystem-ssh2.php:47
WordPress Filesystem Class for implementing SSH2

Description

To use this class you must follow these steps for PHP 5.2.6+

http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/ - Installation Notes

Compile libssh2 (Note: Only 0.14 is officially working with PHP 5.2.6+ right now, But many users have found the latest versions work)

cd /usr/src wget https://www.libssh2.org/download/libssh2-0.14.tar.gz tar -zxvf libssh2-0.14.tar.gz cd libssh2-0.14/ ./configure make all install

Note: Do not leave the directory yet!

Enter: pecl install -f ssh2

Copy the ssh.so file it creates to your PHP Module Directory.
Open up your PHP.INI file and look for where extensions are placed.
Add in your PHP.ini file: extension=ssh2.so

Restart Apache! Check phpinfo() streams to confirm that: ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp exist.

Note: As of WordPress 2.8, this utilizes the PHP5+ function stream_get_contents().

Compatibility

WordPress
since 2.7.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Properties · 4

$keysboolpublic
$optionsarraypublic

Methods · 30

Source code

class WP_Filesystem_SSH2 extends WP_Filesystem_Base { 	/**	 * @since 2.7.0	 * @var resource|false	 */	public $link = false; 	/**	 * @since 2.7.0	 * @var resource|false	 */	public $sftp_link; 	/**	 * @since 2.7.0	 * @var bool	 */	public $keys = false; 	/**	 * @since 7.1.0	 * @var array	 * @phpstan-var Options	 */	public $options; 	/**	 * Constructor.	 *	 * @since 2.7.0	 *	 * @param array $opt {	 *     Array of connection options.	 *	 *     @type string $hostname    Required. SSH server hostname.	 *     @type string $username    Required. SSH username.	 *     @type int    $port        Optional. SSH server port. Default 22.	 *     @type string $password    Optional. SSH password. May be empty when using keys.	 *     @type string $public_key  Optional. Path to public key file for publickey authentication.	 *     @type string $private_key Optional. Path to private key file for publickey authentication.	 * }	 * @phpstan-param array{	 *     hostname: non-empty-string,	 *     username: non-empty-string,	 *     port?: non-negative-int,	 *     password?: string,	 *     public_key?: non-empty-string,	 *     private_key?: non-empty-string,	 * }|null $opt	 */	public function __construct( $opt = null ) {		$this->method  = 'ssh2';		$this->errors  = new WP_Error();		$this->options = array(			'port'     => 22,			'hostname' => '',			'username' => '',			'password' => null,		); 		// Check if possible to use ssh2 functions.		if ( ! extension_loaded( 'ssh2' ) ) {			$this->errors->add( 'no_ssh2_ext', __( 'The ssh2 PHP extension is not available' ) );			return;		} 		if ( ! is_array( $opt ) ) {			$opt = array();		} 		// Set defaults:		if ( ! empty( $opt['port'] ) ) {			$this->options['port'] = $opt['port'];		} 		if ( empty( $opt['hostname'] ) ) {			$this->errors->add( 'empty_hostname', __( 'SSH2 hostname is required' ) );		} else {			$this->options['hostname'] = $opt['hostname'];

Changelog

Introduced in 2.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-admin/includes/class-wp-filesystem-ssh2.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.