当前位置: 首页>>代码示例>>PHP>>正文


PHP ssh2_auth_pubkey_file函数代码示例

本文整理汇总了PHP中ssh2_auth_pubkey_file函数的典型用法代码示例。如果您正苦于以下问题:PHP ssh2_auth_pubkey_file函数的具体用法?PHP ssh2_auth_pubkey_file怎么用?PHP ssh2_auth_pubkey_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ssh2_auth_pubkey_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: connect

 /**
  *
  */
 public function connect()
 {
     $this->ssh = ssh2_connect($this->configuration['hostname'], $this->configuration['port']);
     $username = $this->configuration['username'];
     switch ($this->configuration[SftpDriver::CONFIG_AUTHENTICATION_METHOD]) {
         case static::AUTHENTICATION_PASSWORD:
             ssh2_auth_password($this->ssh, $username, $this->configuration['password']);
             break;
         case static::AUTHENTICATION_PUBKEY:
             $publicKey = $this->configuration['publicKey'];
             $privateKey = $this->configuration['privateKey'];
             if (!file_exists($publicKey) || !file_exists($privateKey)) {
                 return;
             }
             $password = $this->configuration['privateKeyPassword'];
             if (empty($password)) {
                 $password = null;
             }
             ssh2_auth_pubkey_file($this->ssh, $username, $publicKey, $privateKey, $password);
             break;
         default:
     }
     $this->sftp = ssh2_sftp($this->ssh);
     $this->sftpWrapper = 'ssh2.sftp://' . $this->sftp;
     $this->sftpWrapperLength = strlen($this->sftpWrapper);
     $this->iteratorFlags = \FilesystemIterator::UNIX_PATHS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::FOLLOW_SYMLINKS;
     return true;
 }
开发者ID:vertexvaar,项目名称:falsftp,代码行数:31,代码来源:PhpSshAdapter.php

示例2: connect

 /**
  * Connect operation
  */
 public function connect()
 {
     if ($this->_ssh2 != null) {
         // Already connected
         return;
     }
     // Connect to server
     $host = isset($this->_config['hostname']) ? $this->_config['hostname'] : 'localhost';
     $port = isset($this->_config['port']) ? $this->_config['port'] : 22;
     $username = isset($this->_config['username']) ? $this->_config['username'] : '';
     $password = isset($this->_config['password']) ? $this->_config['password'] : null;
     $this->_ssh2 = ssh2_connect($host, $port);
     if ($this->_ssh2 === FALSE) {
         throw new Kohana_Transfer_Exception(Kohana::message('transfer', 'fail_open_connection'), array(':host' => $host, 'port' => $port));
     }
     // Check fingerprint if it is specified
     if (isset($this->_config['fingerprint'])) {
         if (strtolower(ssh2_fingerprint($this->_ssh2)) != strtolower($this->_config['fingerprint'])) {
             throw new Kohana_Transfer_Exception(Kohana::message('transfer', 'fail_fingerprint_validation'), array(':key' => ssh2_fingerprint($this->_ssh2)));
         }
     }
     // Connect with certificate if it is specified
     if (isset($this->_config['pubkeyfile']) and isset($this->_config['privkeyfile'])) {
         if (!@ssh2_auth_pubkey_file($this->_ssh2, $username, $this->_config['pubkeyfile'], $this->_config['privkeyfile'], $password)) {
             throw new Kohana_Transfer_Exception(Kohana::message('transfer', 'fail_authentication'));
         }
     } else {
         if (!@ssh2_auth_password($this->_ssh2, $username, $password)) {
             throw new Kohana_Transfer_Exception(Kohana::message('transfer', 'fail_authentication'));
         }
     }
     // Enable SFTP mode
     $this->_sftp = ssh2_sftp($this->_ssh2);
 }
开发者ID:rpringle,项目名称:transfer,代码行数:37,代码来源:sftp.php

示例3: __construct

 public function __construct($config)
 {
     foreach ($config as $name => $value) {
         $this->{$name} = $value;
     }
     $methods = array();
     if (!isset($this->auth['method'])) {
         error('Unspecified authentication method.');
     }
     // Connect
     $this->connection = ssh2_connect($this->host, isset($this->port) ? $this->port : 22, $methods);
     switch ($this->auth['method']) {
         case 'pubkey':
             if (!isset($this->auth['public'])) {
                 error('Public key filename not specified.');
             }
             if (!isset($this->auth['private'])) {
                 error('Private key filename not specified.');
             }
             if (!ssh2_auth_pubkey_file($this->connection, $this->auth['username'], $this->auth['public'], $this->auth['private'], isset($this->auth['passphrase']) ? $this->auth['passphrase'] : null)) {
                 error('Public key authentication failed.');
             }
             break;
         case 'plain':
             if (!ssh2_auth_password($this->connection, $this->auth['username'], $this->auth['password'])) {
                 error('Plain-text authentication failed.');
             }
             break;
         default:
             error('Unknown authentication method: "' . $this->auth['method'] . '".');
     }
 }
开发者ID:0151n,项目名称:vichan,代码行数:32,代码来源:remote.php

示例4: __construct

 function __construct($cfg)
 {
     // set default options if missing
     static $defaults = array('port' => 22, 'user' => 'root');
     if (is_object($cfg)) {
         $cfg = json_decode(json_encode($cfg), 1);
     }
     foreach ($defaults as $k => $v) {
         if (!isset($cfg[$k])) {
             $cfg[$k] = $v;
         }
     }
     // connect ssh2
     $this->ssh2 = ssh2_connect($cfg['host'], $cfg['port']);
     if (!$this->ssh2) {
         throw new \Exception("can't connect trough ssh2\n");
     }
     // authorize
     if (isset($cfg['key'])) {
         // private/public key authentication requested
         if (!ssh2_auth_pubkey_file($this->ssh2, $cfg['user'], $cfg['key']['pub'], $cfg['key']['pvt'], isset($cfg['key']['pass']) ? $cfg['key']['pass'] : NULL)) {
             throw new \Exception("can't authorize via key");
         }
     } elseif (isset($cfg['pass'])) {
         // username & password authentication
         if (!ssh2_auth_password($this->ssh2, $cfg['user'], $cfg['pass'])) {
             throw new \Exception("can't authorize via user & pass");
         }
     } else {
         throw new \Exception("not enough authentication information provided");
     }
     $this->sftp = ssh2_sftp($this->ssh2);
 }
开发者ID:ngorchilov,项目名称:lgr,代码行数:33,代码来源:ssh2.class.php

示例5: connect

 public function connect()
 {
     $methods = array();
     if ($this->use_pubkey_file_) {
         $methods['hostkey'] = 'ssh-rsa';
     }
     $conn = ssh2_connect($this->conf_['host'], $this->conf_['port'], $methods);
     if (false === $conn) {
         $this->setErr_(-1, sprintf('failed to connect [%s:%d]', $this->conf_['host'], $this->conf_['port']));
         return false;
     }
     if ($this->use_pubkey_file_) {
         $rc = ssh2_auth_pubkey_file($conn, $this->conf_['user'], $this->conf_['pubkey_file'], $this->conf_['privkey_file'], isset($this->conf_['passphrase']) ? $this->conf_['passphrase'] : NULL);
         if (false === $rc) {
             $this->setErr_(-1, sprintf('failed to auth with[%s:%s,%s,%s]', $this->conf_['user'], $this->conf_['pubkey_file'], $this->conf_['privkey_file'], $this->conf_['passphrase']));
             return false;
         }
     } else {
         $rc = ssh2_auth_password($conn, $this->conf_['user'], $this->conf_['passwd']);
         if (false === $rc) {
             $this->setErr_(-1, sprintf('failed to auth with[%s:%s]', $this->conf_['user'], $this->conf_['passwd']));
             return false;
         }
     }
     $this->conn_ = $conn;
     return true;
 }
开发者ID:nicevoice,项目名称:yhtx,代码行数:27,代码来源:Sftp.php

示例6: getOS

function getOS($pass = false)
{
    $ip = $_REQUEST['ip'];
    $sshp = $_REQUEST['sshp'];
    if (!isset($_REQUEST['sshp'])) {
        $sshp = '22';
    }
    $lsbresult1 = array();
    $methods = array('hostkey', 'ssh-rsa');
    if (isset($pass) && $pass) {
        $methods = array();
    }
    $connection = ssh2_connect($ip, $sshp, $methods);
    if (!$connection) {
        throw new Exception("fail: unable to establish connection, please Check IP or if server is on and connected");
    }
    $pass_success = false;
    if ($methods) {
        $rsa_pub = realpath($_SERVER['HOME'] . '/.ssh/id_rsa.pub');
        $rsa = realpath($_SERVER['HOME'] . '/.ssh/id_rsa');
        $pass_success = ssh2_auth_pubkey_file($connection, 'sysad', $rsa_pub, $rsa);
    } else {
        $pass_success = ssh2_auth_password($connection, 'root', $pass);
    }
    if (!$pass_success) {
        throw new Exception("fail: unable to establish connection\nPlease Check your password");
    }
    $cmd = "lsb_release -as";
    $stream = ssh2_exec($connection, $cmd);
    $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
    stream_set_blocking($errorStream, true);
    stream_set_blocking($stream, true);
    $lsbresult1 = stream_get_contents($stream);
    stream_set_blocking($errorStream, false);
    stream_set_blocking($stream, false);
    flush();
    fclose($errorStream);
    fclose($stream);
    fclose($rsa_pub);
    fclose($rsa);
    unset($connection);
    print_r($lsbresult1);
    $lsbresult = explode("\n", $lsbresult1);
    if (!empty($lsbresult)) {
        $OS = $lsbresult[0];
        $version = $lsbresult[3];
        $releasever = $lsbresult[2];
    } else {
        echo "No values present";
        die;
    }
    ssh2_exec($connection, 'exit');
    fclose($stream);
    fclose($errorStream);
    flush();
    unset($connection);
    fclose($connection);
    return array($OS, $version, $releasever);
}
开发者ID:shadowhome,项目名称:synxb,代码行数:59,代码来源:functions.php

示例7: __construct

 public function __construct(FtpConfig $config)
 {
     $this->_config = $config;
     $this->_session = ssh2_connect($this->_config->getHost(), $this->_config->getPort());
     if (!ssh2_auth_pubkey_file($this->_session, $this->_config->getUser(), $this->_config->getPublicKey(), $this->_config->getPrivateKey())) {
         throw new \Exception("Could not connect to Ftp server with provided configuration");
     }
 }
开发者ID:native5,项目名称:native5-sdk-common-php,代码行数:8,代码来源:FtpConnector.php

示例8: authPubkey

 public function authPubkey($user, $pubkeyFile, $privkeyFile, $passphrase)
 {
     if (!ssh2_auth_pubkey_file($this->connection, $user, $pubkeyFile, $privkeyFile, $passphrase)) {
         $this->logs[] = "Public Key Authorization failed";
         return false;
     }
     return true;
 }
开发者ID:nouphet,项目名称:xoops-tpSocialMedia,代码行数:8,代码来源:Ssh2.php

示例9: connect

 public function connect()
 {
     $this->connection = ssh2_connect($this->settings['host'], $this->settings['port']);
     if (!$this->connection) {
         throw new \Exception("Could not connect to remote server.");
     }
     ssh2_auth_pubkey_file($this->connection, $this->settings['user'], $this->settings['publicKey'], $this->settings['privateKey']);
 }
开发者ID:radmiraal,项目名称:PHP-Gerrit-Tools,代码行数:8,代码来源:SSH2.php

示例10: authenticate

 public function authenticate($user, $public_key, $private_key)
 {
     if (!$this->authenticated) {
         if (false === ($this->authenticated = ssh2_auth_pubkey_file($this->connection, $user, $public_key, $private_key))) {
             throw new SshException(sprintf('Authorization failed for user "%s"', $user));
         }
     }
 }
开发者ID:fiunchinho,项目名称:plumber,代码行数:8,代码来源:SshConnection.php

示例11: ssh_connect

function ssh_connect($address)
{
    include 'config.php';
    $tmp = explode(":", $address);
    $ip = $tmp[0];
    $port = $tmp[1];
    global $connection;
    $connection = ssh2_connect($ip, $port, array('hostkey' => 'ssh-rsa'));
    ssh2_auth_pubkey_file($connection, $ssh_user, $ssh_key_path . 'id_rsa.pub', $ssh_key_path . 'id_rsa');
}
开发者ID:BillTheBest,项目名称:kvm-vdi,代码行数:10,代码来源:functions.php

示例12: doLoginPubKey

 protected function doLoginPubKey($user, $pubKeyFile, $privKeyFile, $passphrase = null)
 {
     // try to login
     if (ssh2_auth_pubkey_file($this->getSsh2Connection(), $user, $pubKeyFile, $privKeyFile, $passphrase)) {
         $this->sftp_id = ssh2_sftp($this->getSsh2Connection());
         return $this->sftp_id != false && $this->sftp_id != null;
     } else {
         return false;
     }
 }
开发者ID:richhl,项目名称:kalturaCE,代码行数:10,代码来源:sftpMgr.class.php

示例13: connect

 /**
  *
  * @throws \Exception
  * @return boolean
  */
 public function connect()
 {
     $this->session = ssh2_connect($this->config->host, $this->config->port);
     if (false === $this->session) {
         throw new \Exception("Echec de la connexion ssh " . print_r($this->config->toArray(), true));
     }
     $auth = ssh2_auth_pubkey_file($this->session, $this->config->username, $this->config->pubkeyfile, $this->config->privkeyfile);
     if (true !== $auth) {
         throw new \Exception("Echec de l'authentification ssh " . print_r($this->config->toArray(), true));
     }
     return true;
 }
开发者ID:dsi-agpt,项目名称:minibus,代码行数:17,代码来源:ScpClient.php

示例14: connect

 /**
  * Connect to server
  */
 protected function connect()
 {
     $this->session = ssh2_connect($this->hostname);
     switch ($this->authType) {
         case self::AUTH_PASSWORD:
             ssh2_auth_password($this->session, $this->user, $this->password);
             break;
         case self::AUTH_KEY:
             ssh2_auth_pubkey_file($this->session, $this->user, $this->pubKey, $this->privKey, $this->password);
             break;
     }
 }
开发者ID:p13eater,项目名称:backup-lib,代码行数:15,代码来源:SSH2.php

示例15: connect

 public function connect()
 {
     $this->connection = @ssh2_connect($this->hostname, $this->port, array('hostkey' => 'ssh-rsa'));
     $fingerprint = ssh2_fingerprint($this->connection, SSH2_FINGERPRINT_SHA1 | SSH2_FINGERPRINT_HEX);
     if (!@ssh2_auth_pubkey_file($this->connection, $this->username, $this->pubKeyFile, $this->privKeyFile)) {
         throw new Exception("Authentification Failed");
     }
     $this->sftpSession = @ssh2_sftp($this->connection);
     if (!$this->sftpSession) {
         throw new Exception("Could not initialize SFTP subsystem.");
     }
 }
开发者ID:phpcommerce,项目名称:php-ratepay,代码行数:12,代码来源:SFTPClient.php


注:本文中的ssh2_auth_pubkey_file函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。