/** * @{inheritDoc} */ public function __construct(SessionInterface $session, AuthInterface $auth, OutputInterface $output) { self::registerErrorHandler(); // Set the base object properties parent::__construct($session, $output); $this->printOut('<info>Connecting...</info>'); $this->printDebug('$session => ' . var_export($session, true)); $this->printVerbose('Connecting to ' . $session->getHost() . ' at port ' . $session->getPort()); // Validate ssh2 session if (!$session->valid()) { throw new RuntimeException('SSH connection failed.'); } $this->printVerbose('Connected.'); $this->printDebug('$auth => ' . var_export($auth, true)); $this->printVerbose('Authorize...'); // Authorize try { $authorized = $auth->authorize($session); } catch (ErrorException $e) { throw new RuntimeException('SSH authorization failed. REASON : ' . $e->getMessage()); } $this->printVerbose('Authorized'); $this->session = $session; $this->auth = $auth; $this->printDebug('HOST FINGERPRINT: ' . ssh2_fingerprint($this->session->getConnection())); }
/** * Constructor * * @param SessionInterface * @param OutputInterface * @throws RuntimeException */ public function __construct(SessionInterface $session, OutputInterface $output) { // Set the base object properties parent::__construct($session, $output); if (!$session->valid()) { throw new RuntimeException('SSH connection failed.'); } $this->sftp = ssh2_sftp($session->getConnection()); }