How to copy a file using pscp through an intermediary gateway server hop

pscpputtyssh

I have a linux jump box between me and a remote server. I have seen a few posts on how to do this with scp (e.g. here), but I am on a Windows box, so the situation is slightly different. I want to copy a file from my local windows machine, through a server setup as a gateway between the two. I should be able to do a multi-hop through the intermediate server. So something like this:

A -> B -> C

I don't want to copy the file to B, then log into B and copy the file again. I'd like to be able to run pscp on a number of files to copy them over.

Best Answer

  • I found that the best way to do this is to first establish a tunnel to the intermediate server (server B in the illustration). Then pscp over this link. I'll step through exactly what I did.

    1) Create an SSH connection to serverB in PuTTY

    enter image description here

    2) For this connection create a tunnel that goes from port 2222 (you can pick another if you want) to serverC at port 22

    enter image description here

    3) Open a command window in Windows. Navigate to where PuTTY/pscp is installed on your machine (if not on the Path already)

    4) Enter the following command (substituting your own values for those in {}):

    c:\putty> pscp -P 2222 -pw {myPasswordOnRemoteMachine} c:\dev\fileIWantToCopy.txt {myusername}@127.0.0.1:/tmp

    5) On the remote machineC, the file should be in the /tmp directory