/** * @param $command * * @throws \RuntimeException * @throws \Jumper\Exception\CommunicatorException * @return String */ public function run($command) { $result = $this->ssh->exec($command); if ($result === false) { throw new CommunicatorException($this->ssh->getLastError()); } $error = $this->ssh->getStdError(); if (!empty($error)) { throw new \RuntimeException($error); } return $result; }
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; }