wppaste
WordPress

WP_Filesystem_SSH2

Since
2.7.0
Source
wp-admin/includes/class-wp-filesystem-ssh2.php:36
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 · 3

$keysboolpublic

Methods · 30

Source code

class WP_Filesystem_SSH2 extends WP_Filesystem_Base { 	/**	 * @since 2.7.0	 * @var resource	 */	public $link = false; 	/**	 * @since 2.7.0	 * @var resource	 */	public $sftp_link; 	/**	 * @since 2.7.0	 * @var bool	 */	public $keys = false; 	/**	 * Constructor.	 *	 * @since 2.7.0	 *	 * @param array $opt	 */	public function __construct( $opt = '' ) {		$this->method = 'ssh2';		$this->errors = new WP_Error(); 		// 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;		} 		// Set defaults:		if ( empty( $opt['port'] ) ) {			$this->options['port'] = 22;		} else {			$this->options['port'] = $opt['port'];		} 		if ( empty( $opt['hostname'] ) ) {			$this->errors->add( 'empty_hostname', __( 'SSH2 hostname is required' ) );		} else {			$this->options['hostname'] = $opt['hostname'];		} 		// Check if the options provided are OK.		if ( ! empty( $opt['public_key'] ) && ! empty( $opt['private_key'] ) ) {			$this->options['public_key']  = $opt['public_key'];			$this->options['private_key'] = $opt['private_key']; 			$this->options['hostkey'] = array( 'hostkey' => 'ssh-rsa,ssh-ed25519' ); 			$this->keys = true;		} elseif ( empty( $opt['username'] ) ) {			$this->errors->add( 'empty_username', __( 'SSH2 username is required' ) );		} 		if ( ! empty( $opt['username'] ) ) {			$this->options['username'] = $opt['username'];		} 		if ( empty( $opt['password'] ) ) {			// Password can be blank if we are using keys.			if ( ! $this->keys ) {				$this->errors->add( 'empty_password', __( 'SSH2 password is required' ) );			} else {				$this->options['password'] = null;			}		} else {			$this->options['password'] = $opt['password'];		}	} 	/**	 * Connects filesystem.

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 6.8.8 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.