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

    .......
neubert
  • 15,947
  • 24
  • 120
  • 212
  • 1
    Pro Tip: If your question does not come with a code example, it is probably not On Topic for StackOverflow – RiggsFolly Feb 05 '19 at 11:23
  • Is there a reason why you can't connect directly to the SFTP server? Are you looking more for a VPN maybe? – molamk Feb 05 '19 at 11:25
  • 1
    My work connection as a proxy that refuse me to connect to the SFTP server. We have another proxy to connect to the public internet outside and i need to configure that some how .. sorry about the bad post. @molamk – André Gonçalves Feb 05 '19 at 11:28
  • Do you want to connect from outside to an SFTP server in your work network? – molamk Feb 05 '19 at 11:32
  • No. I want to connect to an outside SFTP server with my work proxy settings that allow me to do that. @molamk – André Gonçalves Feb 05 '19 at 11:36
  • This is too broad of a question, you need to provide more details to have this answered. Also this looks like a system administration issue, so maybe look into https://serverfault.com – molamk Feb 05 '19 at 11:39
  • Perhaps see here: https://stackoverflow.com/q/19161960/3392762 – Progrock Feb 05 '19 at 11:40
  • Im using PHPSECLIB to send a file via SFTP. I want to connect to a server that cant be reach due to security from my company. We have a proxy that allow us to connect to the internet outside our network. I need to configure that to send the file via SFTP. @molamk – André Gonçalves Feb 05 '19 at 11:42
  • @molamk do you understand better now my question? – André Gonçalves Feb 05 '19 at 16:45
  • I don't, sorry. Try to look where @Progrock pointed, and good luck! – molamk Feb 05 '19 at 16:53

1 Answers1

0

Quoting 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

Community
  • 1
  • 1
neubert
  • 15,947
  • 24
  • 120
  • 212