-1

Im using PHPSECLIB to send a file and a XML to a SFTP server. In this case the server im trying to reach is outside my work network. To connect to the internet outside we have a proxy to do that. What i need to do is configure the proxy of this connection to the one i need.

EDIT --

I have the following code, how can i pass the username and password of my proxy ?

   $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);

    .......
4

1 回答 1

0

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

经授权:

$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');

如果这不起作用,请运行脚本并告诉我您返回的标题是什么。摘要式身份验证更像是 PITA,然后是 Basic,但这并非不可能。

有关授权如何与 HTTP 代理一起使用的更多信息:

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

于 2019-02-11T06:09:41.150 回答