phpseclib sftp用私钥和密码连接 [英] phpseclib sftp connect with private key and password

查看:248
本文介绍了phpseclib sftp用私钥和密码连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何,是否可以使用phpseclib或其他任何方法将sftp与私钥和ftp密码连接.

Is there anyway to connect the sftp with both private key and ftp password by using phpseclib or any other method.

推荐答案

SFTP服务器同时使用密码和公钥身份验证是很罕见的.我的猜测是,您最有可能拥有密码保护的私钥.如果是这样,您可以这样登录:

It's kinda rare that SFTP servers use both password and publickey authentication. My guess would be that what you most likely have is a password protected private key. If so you can login thusly:

<?php
include('Net/SFTP.php');
include('Crypt/RSA.php');

$sftp = new Net_SFTP('www.domain.tld');
$key = new Crypt_RSA();
$key->setPassword('whatever');
$key->loadKey(file_get_contents('privatekey'));
if (!$sftp->login('username', $key)) {
    exit('Login Failed');
}

print_r($sftp->nlist());
?>

如果确实您的服务器确实在执行以下两项操作,则应该工作:

If indeed your server truly is doing both the following should work:

<?php
include('Net/SFTP.php');
include('Crypt/RSA.php');

$sftp = new Net_SFTP('www.domain.tld');
$key = new Crypt_RSA();
$key->setPassword('whatever');
$key->loadKey(file_get_contents('privatekey'));
if (!$sftp->login('username', $key) && !$sftp->login('username', 'password')) {
    exit('Login Failed');
}

print_r($sftp->nlist());
?>

这篇关于phpseclib sftp用私钥和密码连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆