Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * @dataProvider configProvider
  */
 public function testStorageId($config, $expectedStorageId)
 {
     $instance = new SFTP($config);
     $this->assertEquals($expectedStorageId, $instance->getId());
 }