PHPSeclib 代理发送用户名和密码作为参数

PHPSeclib Proxy send username and password as arguments

我正在使用 PHPSECLIB 将文件和 XML 发送到 SFTP 服务器。 在这种情况下,我尝试访问的服务器在我的工作网络之外。 要连接到外部的互联网,我们有一个代理来做到这一点。 我需要做的是将此连接的代理配置为我需要的那个。

编辑 --

我有以下代码,如何传递代理的用户名和密码?

   $proxyHost = '******'                             

    $fsock = fsockopen($proxyHost, $proxyPort); 
    $address = '*****'; 
    $port = '*****';
    $request = "CONNECT $address:$port HTTP/1.0\r\nContent-Length: 0\r\n\r\n"; 

    if(fputs($fsock, $request) != strlen($request)) {
        exit("premature termination"); 
    }
    $response = fgets($fsock); 

    $sftp   = new SFTP($fsock);

    .......

引用 https://github.com/phpseclib/phpseclib/issues/1339#issuecomment-462224179:

With authorization:

$fsock = fsockopen('127.0.0.1', 80, $errno, $errstr, 1);
if (!$fsock) {
    echo $errstr; exit;
}
fputs($fsock, "CONNECT website.com:22 HTTP/1.0\r\n");
fputs($fsock, "Proxy-Authorization: Basic " . base64_encode('user:pass') . "\r\n");
fputs($fsock, "\r\n");
while ($line = fgets($fsock, 1024)) {
    if ($line == "\r\n") {
        break;
    }
    //echo $line;
}    
$ssh = new Net_SSH2($fsock);
$ssh->login('user', 'pass');
echo $ssh->exec('ls -latr');

If that doesn't work then run the script and tell me what the headers you get back are. Digest authentication is more of a PITA then Basic but it's not impossible.

More info on how authorization works with HTTP proxies:

https://www.rfc-editor.org/rfc/rfc7235#section-4.3