I wonder if there is a way for me to SCP the file from remote2 host directly from my local machine by going through a remote1 host.
The networks only allow connectio
sshEven in your complex case, you can handle file transfer using a single command line, simply with ssh ;-)
And this is useful if remote1 cannot connect to localhost:
ssh user1@remote1 'ssh user2@remote2 "cat file"' > file
tarBut you loose file properties (ownership, permissions...).
However, tar is your friend to keep these file properties:
ssh user1@remote1 'ssh user2@remote2 "cd path2; tar c file"' | tar x
You can also compress to reduce network bandwidth:
ssh user1@remote1 'ssh user2@remote2 "cd path2; tar cj file"' | tar xj
And tar also allows you transferring a recursive directory through basic ssh:
ssh user1@remote1 'ssh user2@remote2 "cd path2; tar cj ."' | tar xj
ioniceIf the file is huge and you do not want to disturb other important network applications, you may miss network throughput limitation provided by scp and rsync tools (e.g. scp -l 1024 user@remote:file does not use more than 1 Mbits/second).
But, a workaround is using ionice to keep a single command line:
ionice -c2 -n7 ssh u1@remote1 'ionice -c2 -n7 ssh u2@remote2 "cat file"' > file
Note: ionice may not be available on old distributions.