How do you proxy though a server using ssh (socks…) using php’s CURL?

后端 未结 5 879
梦谈多话
梦谈多话 2021-02-10 00:27

I want to use ssh, something like this:

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

But within php CURL, but I don\'t really see how this cou

5条回答
  •  既然无缘
    2021-02-10 01:00

    You can use both libssh2 and curl from within a PHP script.

    • First you need to get the ssh2 library from the PECL site. Alternatively, the PEAR package has SSH2 support too.
    • After installing you can then read the ssh2 documentation on setting up a tunnel.
    • In your script you can then set up the tunnel.
    • After the tunnel is set up in the script you can specify the CURL proxy.
    • Perform your CURL operation.
    • Release the tunnel resource and close the connection in your script.

    I'm not a PHP expert, but here's a rough example:

    
    

    The simplest option

    Another option to consider is using sftp (ftp over ssh) instead of CURL... this is probably the recommended way to copy a file from one server to another securely in PHP...

    Even simpler example:

    
    

提交回复
热议问题