本文整理汇总了PHP中Net_SSH2::getMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP Net_SSH2::getMessage方法的具体用法?PHP Net_SSH2::getMessage怎么用?PHP Net_SSH2::getMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Net_SSH2
的用法示例。
在下文中一共展示了Net_SSH2::getMessage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exec
/**
* Execute the specified command.
*
* @param string $std_output The standard output of the executed command
* @param string $std_error The standard error of the executed command
*
* @throws Net_SSH2_Exception If the system does not support PTY.
*
* @return mixed The exit code of the executed command or false on error
*/
protected function exec($command, &$std_output, &$std_error)
{
$exit_code = false;
//This value can be set in the createCommandLine method implementation
$std_input = $this->_std_input;
$descriptorspec = array(0 => array("pty"), 1 => array("pty"), 2 => array("pty"));
try {
$process = proc_open($command, $descriptorspec, $pipes);
} catch (Exception $e) {
if ($this->password !== null) {
//Only public/private key authentication is supported.
throw new Net_SSH2_Exception(Net_SSH2::getMessage(SSH2_PTY_NOT_SUPPORTED, $e->getMessage()));
}
exec($command, $std_output, $exit_code);
return $exit_code;
}
if (is_resource($process)) {
stream_set_blocking($pipes[0], false);
stream_set_blocking($pipes[1], false);
stream_set_blocking($pipes[2], false);
if ($std_input !== null) {
$std_output .= fgets($pipes[1], 4096);
sleep(2);
fwrite($pipes[0], $std_input . "\n");
fflush($pipes[0]);
}
while (!feof($pipes[1])) {
$std_output .= fgets($pipes[1], 4096);
}
while (!feof($pipes[2])) {
$std_error .= fgets($pipes[2], 4096);
}
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
$exit_code = proc_close($process);
}
return $exit_code;
}
示例2: sshCopyId
/**
* Install your public key in a remote machine’s authorized_keys
*
* @param string $std_output The standard output of the executed command
* @param string $std_error The standard error of the executed command
* @param array $options Additional options for the specified method
*
* @throws Net_SSH2_Exception If the public key is not found.
*
* @return mixed The exit code of the executed command or false on error
*/
public function sshCopyId(&$std_output, &$std_error, $options = array())
{
//Check for valid options
foreach ($options as $key => $value) {
$this->{$key} = $value;
}
if (!is_readable($this->public_identity_file)) {
throw new Net_SSH2_Exception(Net_SSH2::getMessage(SSH2_PUBLIC_KEY_UNAVAILABLE));
}
$exit_code = 255;
$pub_key = trim(File::readAll($this->public_identity_file), "\n");
$pub_key_array = explode(' ', $pub_key);
try {
$connection = $this->_authenticate($std_output);
$pkey = ssh2_publickey_init($connection);
ssh2_publickey_add($pkey, $pub_key_array[0], base64_decode($pub_key_array[1]), false, array('comment' => $pub_key_array[2]));
$exit_code = 0;
} catch (Exception $e) {
$std_output = $e->getMessage();
}
return $exit_code;
}
示例3: __set
/**
* Overloading of the __set method
*
* @param string $key The name of the properties that should be set
* @param mixed $value parameter specifies the value that the object
* should set the $key
*
* @throws Net_SSH2_Exception If trying to set an undefined properties.
* @return mixed True on success
*/
public function __set($key, $value)
{
if (!key_exists($key, $this->allowed_options)) {
throw new Net_SSH2_Exception(Net_SSH2::getMessage(SSH2_OPTION_NOT_VALID, $key));
}
$this->options[$key] = $value;
return true;
}