SSH: transfer files indirectly using scp

15 January 2016

Many times I have to remotely transfer files between 2 Hosts. And sometimes those hosts are not able to communicate to each other. In order to copy a file from host1 to host2 I had to copy it to my workstation first. But this is not necessary…

It is possible to execute scp like this:

host2host-> scp user@host1:/somefile user@host2:/somefile

In this example host1 and host2 are able to communicate together(user exist and perhaps ssh-keys too). I execute scp on host3 but the files are copied between host1 and host2. But what if host1 and host2 are not able to contact each other? For those cases I found a wonderful scp-switch in the manual:

-3 Copies between two remote hosts are transferred through the local host. Without
this option the data is copied directly between the two remote hosts. Note that
this option disables the progress meter.

redirected -> scp -3 user@host1:/somefile user@host2:/somefile

[ Linux  Sysadmin  Tricks  ssh  ]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 Unported License.

Copyright 2015-present Hoti