A one-liner? Not off the top of my head. You need to establish a proxy first and you can't do that with scp by itself.
When doing it manually, I open up a screen session for my tunnel:
screen -S tunnel
Screen is used to keep the tunnel going in a background shell. Use any technique you want to keep the tunnel open in the background (@weeheavy's answer is probably the simplest). Once in the screen session I start my tunnel like so
ssh -L 2222:target.machine:22 [user@]proxy.machine
To break that down, that basically says "On my local machine, open port 2222 and any connetion hitting localhost:2222 is proxied through proxy.machine to target.machine:22"
Once you've got the ssh connection and tunnel established, detach from the screen session with "C-a d". To get back to that screen session, type screen -raAd tunnel
Once you are back in your original shell your scp command will look like
scp -P 2222 localhost:your/file/on/target.machine local/path
Remember that localhost port 2222 is really just a tunnel going to target.machine.
How can we copy from local machine to target machine with proxy? – Mulagala – 2017-11-16T11:34:57.050
5Just a quick note. If you are using an alternative identity file via the -i command line option for ssh, you need to specify that option for both the ProxyCommand configuration and the ssh command line. – BillMan – 2013-05-15T18:32:57.960
73 things that might help, 1) it would help if you also showed the
Host proxy.machine
lines in the same~/.ssh/config
file, 2) Mention whether these commands can be nested (ie. client connects to proxy host 1 which connects to proxy host 2 which connects to...target) and 3) whatnc %h %p
means – puk – 2013-11-14T06:00:38.530