当前位置: 首页>>代码示例>>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;未经允许,请勿转载。