Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy multiple files simultaneously using scp

Tags:

linux

scp

I would like to copy multiple files simultaneously to speed up my process I currently used the follow

scp -r [email protected]:/var/www/example/example.example.com .

but it only copies one file at a time. I have a 100 Mbps fibre so I have the bandwidth available to really copy a lot at the same time, please help.

like image 929
Philip Avatar asked Jan 19 '15 12:01

Philip


1 Answers

You can use background task with wait command. Wait command ensures that all the background tasks are completed before processing next line. i.e echo will be executed after scp for all three nodes are completed.

#!/bin/bash
scp -i anuruddha.pem myfile1.tar [email protected]:/tmp &
scp -i anuruddha.pem myfile2.tar [email protected]:/tmp &
scp -i anuruddha.pem myfile.tar [email protected]:/tmp &

wait
echo "SCP completed"
like image 117
Anuruddha Lanka Liyanarachchi Avatar answered Sep 23 '22 04:09

Anuruddha Lanka Liyanarachchi