linux - How to download a file using scp over two hops
2014-04
As the title says, how can I download a file using scp over two hops? Preferably, the files must not be stored (written to disk) at any point in the first server, just transfered through.
Using simply :
scp user1@host1:/location/of/file user2@host2:/location/of/destination
If you have a traffic forwarder (netcat, socat, etc.):
scp -o ProxyCommand="ssh FIRST_HOP socat tcp:SECOND_HOP:22 stdio" \
FIRST_HOP:/path/on/second_hop/file local/path/
I have connected to a Unix server using SSH from my terminal from my Windows client.
How do I copy files from the Unix server to the Windows client? Can I use the scp and rcp commands? Or are there other ways to do so?
scp
is the way that we do this. If you're using something like putty, it comes with pscp
as part of it.
I prefer pscp
over the standard scp
since it allows you to specify a password on the command line, something useful for scripting.
An example invocation from one of my scripts (details changed to protect the innocent):
pscp -pw paxpwd src.tar.gz [email protected]:/usr/pax/tmp/src.tar.gz
This copies the src.tar.gz
file from my local (Windows) directory to /usr/pax/tmp
on my pax.com
UNIX machine, using the pax/paxpwd
user and password.
Your particular use case would be satisfied by:
pscp -pw biranchipwd [email protected]:abc/xyz.txt xyz.txt
Keep in mind that placing passwords into scripts is not generally a good idea since it means anyone that breaks into your local machine can easily break into the other machine as well.
You can use scp directly on the command prompt itself: For example:
c:>scp [email protected]:/home/myuser/test.properties .
[email protected]'s password:
test.properties 100% 675 0.7KB/s 00:00