A SOCKS5 proxy is between my source and target servers. The source server can be accessed only from my local server.

I tried connecting through proxy option and SSH tunneling option in Winscp but the problem is as below:

The SOCKS5 proxy is used only for my source server(tunneled one) instead, I would like to use it for my target server. Please let me know how I can achieve this.

Flow: Local system -> Source server -> SOCKS5 proxy -> Target server

  • Can you connect with ssh or sftp from the source server command-line to the target server? Jul 20, 2019 at 6:43
  • No, there is a firewall in between and only the socks5 proxy can connect to target server
    – Raavi
    Jul 20, 2019 at 20:09
  • We know. But if you want to connect local > source > proxy > target, then you first need to be able to connect source > proxy > target. Or I do not understand your question. Jul 21, 2019 at 8:02
  • Ok. Yes. The connections works. I have tested using the curl command. curl --socks5 proxyhost:1080 sftp://targethost:22 -user user_name: --key /home/wmadmin/.ssh/private_key
    – Raavi
    Jul 21, 2019 at 9:22

1 Answer 1


So you are connecting local > source > proxy > target.

First test a connection from source via proxy to the target using OpenSSH ssh command.

This should help you: How can I use SSH with a SOCKS 5 proxy?

The command will be like (untested):

ssh -o ProxyCommand='/usr/bin/nc -X 5 -x proxyhost:1080 %h %p' user@host

The connection has to work without any intervention (so it would typically need to authenticate using an unencrypted private key).

Once you have that working, you can go to WinSCP (running on local) and configure it as if you were connecting to source. But additionally, on Environment > SFTP page on Advanced site settings dialog, specify the "SFTP server" using the ssh command you have just made working on source. Just add -s sftp switch:

ssh -o ProxyCommand='/usr/bin/nc -X 5 -x proxyhost:1080 %h %p' -s sftp user@host
  • I have tried this command before. But nc is not installed and I'm not the administrator to install nc. I think there no way for me to connect through ssh to target :(
    – Raavi
    Jul 21, 2019 at 10:17
  • Did you try simple nc (without a path)? Maybe it's installed to a different folder. nc is pretty much a standard tool. Jul 21, 2019 at 10:31
  • You can also implement nc equivalent using any scripting language that you have on the source, like Perl, PHP or Python. This looks like it might do what you need: github.com/dzonerzy/Pync/blob/master/nc.py (not tested). - I would not be surprised, if it was possible to use curl as nc replacement either. Jul 21, 2019 at 11:12
  • Yes I tried nc and it says "-ksh: nc: not found [No such file or directory]". I can connect using curl but it does not offer same functionality as ssh. I will try if I can find something from script nc.py. Thanks for it.
    – Raavi
    Jul 21, 2019 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.