本文整理汇总了PHP中Net_SSH2::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP Net_SSH2::getErrors方法的具体用法?PHP Net_SSH2::getErrors怎么用?PHP Net_SSH2::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Net_SSH2
的用法示例。
在下文中一共展示了Net_SSH2::getErrors方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ssh_connect
function ssh_connect($host)
{
dbg_log("Connecting over SSH to {$host}");
#define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
$ssh = new Net_SSH2($host);
$key = new Crypt_RSA();
$key->setPassword(get_config()->host_ssh_private_key_password);
$keyPath = get_config()->host_ssh_private_key;
$keyString = file_get_contents($keyPath);
$userString = get_config()->host_ssh_username;
if (!$key->loadKey($keyString)) {
dbg_log(var_dump($ssh->getErrors(), true));
exit("cannot import key {$keyPath}");
}
if (!$ssh->login($userString, $key)) {
dbg_log($ssh->getLastError());
exit('Login Failed');
}
return $ssh;
}
示例2: checkCmdExceptions
/**
* Run this method after executing a command to detect errors
* @param \Net_SSH2 $handle
* @throws \Cogeco\Build\Exception
*/
protected static function checkCmdExceptions(\Net_SSH2 $handle)
{
if ($handle->getExitStatus() > 0) {
throw new Exception("Command failed with exit status " . $handle->getExitStatus() . "\n\t" . implode("\n\t", $handle->getErrors()));
} else {
if (count($handle->getErrors())) {
throw new Exception(__CLASS__ . ": Command failed.\n\t" . implode("\n\t", $handle->getErrors()));
}
}
}
示例3: getErrors
public function getErrors()
{
return $this->ssh->getErrors();
}
示例4: createSSHHandler
/**
* @param array $config
*
* @return \Net_SSH2
* @throws \Exception
*/
private function createSSHHandler(array $config)
{
$ssh = new \Net_SSH2($config['hostname'], $config['port'], $config['timeout']);
$password = $this->getPassword($config);
if (empty($config['rsa_key'])) {
$login = $ssh->login($config['username'], $password);
$type = 'password';
} else {
$login = $ssh->login($config['username'], $this->getKey($config, $password));
$type = 'key';
}
if ($login !== true) {
throw new \Exception(sprintf("Failed logging in to %s@%s:%d. Using type: %s. \nErrors: %s", $config['username'], $config['hostname'], $config['port'], $type, json_encode($ssh->getErrors(), true)));
}
return $ssh;
}