Abhishek dot py Abhishek dot py - 1 year ago 52
Linux Question

Send multiple file to multiple location using scp

I need to send multiple files to multiple location, but can't find the proper way.

e.g. I need to send file1 to location1 and file2 to location2. This is what I am doing:

scp file1 file2 root@ /location2

But this is not working. Any suggestion?


It's not possible to send to multiple remote locations with a single scp command. It can accommodate multiple source files but only one destination. Using just the scp command itself, it must be run twice.

scp file1 file2 user@ 
scp file1 file2 user@

It is possible to turn this into a "one-liner" by running a for loop. In bash for example:

for REMOTE in "user@" "user@"; do scp file1 file2 $REMOTE; done

scp still runs multiple times but the loop takes care of the iteration. That said, I find it easier to run the command once, hit the Up Arrow (which brings the original command back up in most environments) and just change the remote location and resend.