Ssh – How to use a remote server as a proxy to download file

PROXYscpsshwget

There are some http file links I can not access, but I have a remote server which can access them.

To download these files to my machine, I use the remote server as a "proxy". This is what I did:

  1. ssh to remote server
  2. execute wget command on remote server to download the file
  3. transfer the downloaded file to my machine through scp command

I want to ask if there exist more convenient method to achieve it? like:

some_command root@server http://xxxxx/file.zip ~/Desktop/

Thanks:)

Best Answer

ssh provides a convenient TCP SOCKS5 proxy mode with its -D/DynamicForward option (let's use the default SOCKS port: 1080, you can use any port as long as its referenced in the later settings):

ssh -D 1080 someuser@server

You can instead run the ssh command in background so it stays available without needing to keep it in a terminal for later:

ssh -f -o ExitOnForwardFailure=yes -D 1080 someuser@server

Unfortunately wget itself doesn't support the SOCKS protocol. curl is fine with it with either:

export http_proxy=socks5h://localhost:1080/ https_proxy=socks5h://localhost:1080/
curl -o ~/Desktop/file.zip http://xxxxx/file.zip

or just:

curl --socks5-hostname localhost:1080 -o ~/Desktop/file.zip http://xxxxx/file.zip

If you really need wget you must use a wrapper. For example there's proxychains which relies on LD_PRELOAD interception (there are others, like dante's socksify client wrapper working in a similar way or redsocks which itself relies on a special firewall setup for interception).

mkdir ~/.proxychains
(echo strict_chain; echo proxy_dns; echo '[ProxyList]'; echo socks5 127.0.0.1 1080) > ~/.proxychains/proxychains.conf

proxychains wget http://xxxxx/file.zip ~/Desktop/
Related Question