Sending multiple files to multiple locations using scp

I need to send multiple files to multiple locations, but cannot find the correct path.

eg. I need to send file1 to location1 and file2 to location2. This is what I do:

scp file1 file2 root@192.168.1.114 :/location1 /location2 

But that does not work. Any suggestion?

+4
source share
5 answers

It is not possible to send multiple remote locations with a single scp command. It can hold several source files, but only one destination. Using only the scp command, you need to run it twice.

 scp file1 file2 user@192.168.1.114 :/location1 scp file1 file2 user@192.168.1.114 :/location2 

You can turn this into a "one-liner" by running the for loop. In bash for example:

 for REMOTE in " user@192.168.1.114 :/location1" " user@192.168.1.114 :/location2"; do scp file1 file2 $REMOTE; done 

scp still executes several times, but the loop iterates. However, it’s easier for me to run the command once, press the up arrow (which returns the original command in most environments) and just change the remote location and resend.

+4
source

you can put your scp command in a .sh file and execute scp commands with username and password on one line

vim ~ / fileForSCP.sh

 #!/bin/sh sshpass -p {password} scp file1 root@192.168.1.114 :/location1 sshpass -p {password} scp file2 root@192.168.1.114 :/location2 sshpass -p {password} scp file3 root@192.168.1.114 :/location3 ... sshpass -p {password} scp file{n} root@192.168.1.114 :/location{n} 


and then:

 chmod 777 ~/fileForSCP.sh ~/fileForSCP.sh 
+2
source

You cannot do this with a single scp command. Just use scp twice:

 scp file1 root@192.168.1.114 :/location1 scp file2 root@192.168.1.114 :/location2 
+1
source

Hi, there is a problem with this request, since SCP is only aimed at one purpose, but warns that this may be a bit naive, but it does your job. use the && operator between two SCP calls

I use it as follows:

 scp fileTosend userName1@IPAddress _1:path/to/folder && scp fileToSend userName2@IPAddress _2:path/to/folder 

This will simultaneously send data to both destinations.

+1
source

you can create the desired remote tree structure using sim links for example

ln -s file1 target / location1 / file1 ... etc.

after that you can use a dereferencing copy to click these files

rsync -rL target -e ssh user @host: / tmp

0
source

Source: https://habr.com/ru/post/1491321/


All Articles