WP_Filesystem_SSH2::run_command() WordPress Method

The SSH2::run_command() method is used to execute a command on a remote server via an SSH connection. This method returns the output of the command as a string.

WP_Filesystem_SSH2::run_command( string $command, bool $returnbool = false ) #


Parameters

$command

(string)(Required)

$returnbool

(bool)(Optional)

Default value: false


Top ↑

Return

(bool|string) True on success, false on failure. String if the command was executed, $returnbool is false (default), and data from the resulting stream was retrieved.


Top ↑

Source

File: wp-admin/includes/class-wp-filesystem-ssh2.php

	public function run_command( $command, $returnbool = false ) {
		if ( ! $this->link ) {
			return false;
		}

		$stream = ssh2_exec( $this->link, $command );

		if ( ! $stream ) {
			$this->errors->add(
				'command',
				sprintf(
					/* translators: %s: Command. */
					__( 'Unable to perform command: %s' ),
					$command
				)
			);
		} else {
			stream_set_blocking( $stream, true );
			stream_set_timeout( $stream, FS_TIMEOUT );
			$data = stream_get_contents( $stream );
			fclose( $stream );

			if ( $returnbool ) {
				return ( false === $data ) ? false : '' !== trim( $data );
			} else {
				return $data;
			}
		}

		return false;
	}


Top ↑

Changelog

Changelog
VersionDescription
2.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.