當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Net_SFTP::getServerPublicHostKey方法代碼示例

本文整理匯總了PHP中Net_SFTP::getServerPublicHostKey方法的典型用法代碼示例。如果您正苦於以下問題:PHP Net_SFTP::getServerPublicHostKey方法的具體用法?PHP Net_SFTP::getServerPublicHostKey怎麽用?PHP Net_SFTP::getServerPublicHostKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Net_SFTP的用法示例。


在下文中一共展示了Net_SFTP::getServerPublicHostKey方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 public function __construct($params)
 {
     // The sftp:// scheme has to be manually registered via inclusion of
     // the 'Net/SFTP/Stream.php' file which registers the Net_SFTP_Stream
     // stream wrapper as a side effect.
     // A slightly better way to register the stream wrapper is available
     // since phpseclib 0.3.7 in the form of a static call to
     // Net_SFTP_Stream::register() which will trigger autoloading if
     // necessary.
     // TODO: Call Net_SFTP_Stream::register() instead when phpseclib is
     //       updated to 0.3.7 or higher.
     require_once 'Net/SFTP/Stream.php';
     $this->host = $params['host'];
     $proto = strpos($this->host, '://');
     if ($proto != false) {
         $this->host = substr($this->host, $proto + 3);
     }
     $this->user = $params['user'];
     $this->password = $params['password'];
     $this->root = isset($params['root']) ? $this->cleanPath($params['root']) : '/';
     if ($this->root[0] != '/') {
         $this->root = '/' . $this->root;
     }
     if (substr($this->root, -1, 1) != '/') {
         $this->root .= '/';
     }
     $hostKeys = $this->readHostKeys();
     $this->client = new \Net_SFTP($this->host);
     // 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->password)) {
         throw new \Exception('Login failed');
     }
 }
開發者ID:Combustible,項目名稱:core,代碼行數:42,代碼來源:sftp.php

示例2: getConnection

 /**
  * Returns the connection.
  *
  * @return \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 \Net_SFTP($this->host);
     // 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->password)) {
         throw new \Exception('Login failed');
     }
     return $this->client;
 }
開發者ID:heldernl,項目名稱:owncloud8-extended,代碼行數:28,代碼來源:sftp.php


注:本文中的Net_SFTP::getServerPublicHostKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。