I dislike calling scp twice.

I need to connect to box1 via ssh the again to boxNAME. How do i copy a file from boxNAME to my local drive? also how do i copy a file from my local drive back to boxNAME?

alternatively if i can grab a file (either one) and output it and use it as a stdin on the other side that would work just as well. (The files are <4k and text). Bonus point if you can tell me how to create a text document and use stdout to write and save (remember this is across 2 connections not local in which case i'd do cat file >>out.txt)


Have you tried something like this ?

ssh user@host1 "ssh user@host2 'cat file.txt' " > local_file.txt

I think the easiest method might be to simply use port forwarding. Start a session to the intermediate box and forward some port to allow ssh connection to the far host. Then simply use scp via your port forward.

If you need to do this regularly, you could create a ssh configuration that uses the ProxyCommand directive.

Host farhost
    ProxyCommand /usr/bin/ssh username@intermediate "/bin/netcat -w 1 farhost 22"
    User username

Given something like the above you can make connections to the far host as if it was directly connected. For this to work the best you'll want to setup key-based authentication.

Your Answer

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