How to rsync only a specific list of files to the same location on another server

awkrsyncscp

I have a list of files:
/location/file.txt

Content of file:

/location1/file2.abc
/location2/location3/file1.abc
/location4/location5/fileX.cde

I'd like to copy files to another sever like this:

cat /location/file.txt | xargs -i scp {} user@server:/location

but in the above example all of files from the list are copying to specific location, while I'd like to copy them to the same locations (accurate path as in the txt file /location1/, /location2/location3/ etc.

How can I do it? I can also use rsync, but I'd like to enter password (to remote server) only once.

Best Answer

rsync -av --files-from=/location/file.txt / user@server:/location/

That will copy the local file /location1/file2.abc to /location//location1/file2.abc etc.

As rsync will invoke ssh only once, you only have to enter the password once. You may want to investigate using ssh keys though.

Related Question