/** * Returns the connection. * * @return \phpseclib\Net\SFTP connected client instance * @throws \Exception when the connection failed */ public function getConnection() { if (!is_null($this->client)) { return $this->client; } $hostKeys = $this->readHostKeys(); $this->client = new \phpseclib\Net\SFTP($this->host, $this->port); // The SSH Host Key MUST be verified before login(). $currentHostKey = $this->client->getServerPublicHostKey(); if (array_key_exists($this->host, $hostKeys)) { if ($hostKeys[$this->host] != $currentHostKey) { throw new \Exception('Host public key does not match known key'); } } else { $hostKeys[$this->host] = $currentHostKey; $this->writeHostKeys($hostKeys); } if (!$this->client->login($this->user, $this->auth)) { throw new \Exception('Login failed'); } return $this->client; }
public function __construct($params) { parent::__construct($params); $this->publicKey = $params['public_key']; $this->privateKey = $params['private_key']; }