How do you use a proxy server using ssh server (socks ...) using phps CURL?

I want to use ssh, something like this:

ssh -D 9999 username@ip-address-of-ssh-server

But in php CURL, but I really don't see how this can be done?

I noticed "CURLPROXY_SOCKS5" as a type on a php site, but I think that this will not work, since it is not really socks, its ssh ...

I am currently using this code:

curl_setopt($ch, CURLOPT_PROXY, ‘ip:port'); 

But I use a free proxy and its rather slow and unreliable, I also send confidential information on this proxy. That's why I want to proxy it on a save server that I trust, but I only have the ssh setting and it was not able to host the proper proxy.

+5
source share
5 answers

libssh2, curl PHP script.

  • ssh2 PECL. , PEAR SSH2.
  • ssh2 .
  • script .
  • , script, - CURL.
  • CURL.
  • script.

PHP, :

<?php
$connection = ssh2_connect(ip-address-of-ssh-server, 22);
ssh2_auth_pubkey_file($connection, 'username', 'id_dsa.pub', 'id_dsa');
$tunnel = ssh2_tunnel($connection, '127.0.0.1', 9999);
curl_setopt($ch, CURLOPT_PROXY, ‘127.0.0.1:9999'); 
// perform curl operations

// The connection and tunnel will die at the and of the session.
?>

sftp (ftp over ssh) CURL... , , PHP...

:

<?php
$connection = ssh2_connect(ip-address-of-ssh-server, 22);
ssh2_auth_password($connection, 'username', 'password');
ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644);
?>
+4

manpage -D - socks.

-D [bind_address:]port
             Specifies a local ``dynamic'' application-level port forwarding.
             This works by allocating a socket to listen to port on the local
             side, optionally bound to the specified bind_address.  Whenever a
             connection is made to this port, the connection is forwarded over
             the secure channel, and the application protocol is then used to
             determine where to connect to from the remote machine.  Currently
             the SOCKS4 and SOCKS5 protocols are supported, and ssh will act
             as a SOCKS server.  Only root can forward privileged ports.  Dy-
             namic port forwardings can also be specified in the configuration
             file.
+2

ssh2 ssh2_tunnel, ssh tunnel throu. : http://www.php.net/manual/en/function.ssh2-tunnel.php

0

Qwerty . , , . cURL . , SSH , ?

http://www.cacert.org/

, , . ssh!

0

SSH script, , , PHP forks. SSH- (-D - , , ), CURL - socks. , ssh, .

, , , , . , -L 1234: remotehost: 80 URL http://localhost:1234/some/uri

If this goes wrong, you can find the aspen SSH tunnels on your server, so I would call it somewhat fragile.

0
source

All Articles