Is it possible to copy multiple files from multiple directories at once from server A to server B?

How can i copy multiple different files from different directories from one server to another server? Is there a script that could be written for it?
Can i list the location of files in a touch file and use that within a command syntax to copy it all at once?
Who is Participating?
scp 'server1:/home/{file_a, file_b, file_c...}'
quotes added or you would have to escape the curly brackets

scp server1:/home/file_a server1:/home/file_b server1:/home/file_c ... destination_server:/home/
may be easier to type

if you wanted something to automatically copy all the files but 30 by 30, you can code a simple one-liner

find /home/ -type f -print | sed 's/.*/server1:&/' | xargs -n 30 scp

i tryed to be compatible with most unix-like systems, but you may need to adjust
It will be a long procedure......copy one by one.....its the easiest, safer and the simple way.
is the destination the same directory for all files?
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Is the goal to update a directory(s) on one machine with data from another machine? If so rsync would be the best solution. We need a bit more information to suggest the best solution.
rsync with a file-list would be my preferred way of doing it.
Duncan RoeSoftware DeveloperCommented:
@assistunix: please tell us in more detail what exactly it is that you want to do.
There are a number of suggestions above, and I have another one: do you want to copy a number of files from various places in one system to the same places on another?
The reason I ask is that I developed a script like that at work. It uses a text file to generate ftp commands to do the job
scp /path/to/file/1 /different/path/to/file/2 destination_host:/destination/path

should also work using rcp, sftp, ftp ..


if you need to do multiple copies of multiple files to different location, some of these commands can be driven interactively (so consider expect) or use batch files.

much simpler, use tar over telnet, rlogin, or ssh

tar cvf - /path/to/file /other/path ... | ssh ... | tar xvf -

it should be pretty easy to script any of this

obviously consider rsync as well
assistunixAuthor Commented:
Yes- the source server and the target server both have same dir location.
there are 30 files in /home on serverA which i want to copy to /home on serverB.

Instead of doing it one by one- I would like to be able to do it all at once.
How can i do that?
scp "server1:/home/*" server2:/home

maybe with some extra switshes will do.

Yes- the source server and the target server both have same dir location.

read our posts and/or the scp man page : this is irrelevant.
what is relevant is wether you copy all the files TO the same location or not
(see first line of my post)
actually you could even copy files from different servers

there are 30 files in /home on serverA which i want to copy to /home on serverB.

 this is inconsistent with your original question

multiple different files from different directories

given this new information, use either of these commands

scp server1:/home/* server2:/home/


scp -r server1:/home/ server2:/
assistunixAuthor Commented:
scp server1:/home/* server2:/home/  won't help me.

My last post was an example to make the question simpler, clearly it didn't.

Let me clarify it further.
I have 100+ files in /home on serverA.
What i want to do is, copy 30 of those 100 files all at once from /home serverA to /home ServerB.
Well then you have to qualify which files you want to copy you always can write:
scp server1:/home/{file_a, file_b, file_c...}
and you can achieve that with an include/exclude file.

What you must do of course is "filtering" for the files you like to transfer.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.