PHP-通过socks5代理从私钥连接到sftp

问题描述 投票:0回答:1

我正在尝试通过代理通过rsa私钥auth连接到sftp。

use phpseclib\Net\SFTP;
use phpseclib\Crypt\RSA;

$proxyHost = 'proxy-host';
$proxyPort = 1080;
$fsock = fsockopen($proxyHost, $proxyPort);

$host = 'sftp.hostname.com';
$login = 'sftp_login';
$privatekey = file_get_contents('sftp_private.ppk');
$password = new RSA();
$password->loadKey($privatekey);
$request = "CONNECT $host:22 HTTP/1.0\r\nContent-Length: 0\r\n\r\n";

if(fputs($fsock, $request) != strlen($request)) {
  exit("premature termination");
}
while ($line = fgets($fsock, 1024)) {
    if ($line == "\r\n") {
      break;
    }
    //echo $line;
}
$sftp = new SFTP($fsock);
if (!$sftp->login($login, $password)) {
  exit('Login Failed');
}

我得到“登录失败”出口。

谢谢

php curl proxy phpseclib fsockopen
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.