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 [email protected]:/location1 /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 [email protected]:/location1
scp file1 file2 [email protected]:/location2
It is possible to turn this into a "one-liner" by running a for loop. In bash for example:
for REMOTE in "[email protected]:/location1" "[email protected]:/location2"; 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.
you can put your scp command in .sh file and execute scp commands with the user name and password in one line
vim ~/fileForSCP.sh
#!/bin/sh
sshpass -p {password} scp file1 [email protected]:/location1
sshpass -p {password} scp file2 [email protected]:/location2
sshpass -p {password} scp file3 [email protected]:/location3
...
sshpass -p {password} scp file{n} [email protected]:/location{n}
and then:
chmod 777 ~/fileForSCP.sh
~/fileForSCP.sh
You cannot do it with single scp
command. Just use scp
twice:
scp file1 [email protected]:/location1
scp file2 [email protected]:/location2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With