Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scp a bunch of files via bash script: there must be a better way

Tags:

bash

loops

scp

I currently have the following bash script:

for a in `seq 16 75`; 
do scp doneill@server:/mnt/device/folder/numbered_file$a.txt ./; 
done;

while this does work, it is very slow. Each file, the request to the sever takes about 4-7 seconds, then sending the file takes another 3 or so seconds.

Is there a way to do this that involves only 1 command sent to the server (to minimize the time my VPN spends sending receiving each individual command)? Normally, I would do something like scp doneill@server:/mnt/device/folder/numbered_file* but there are many thousands of files in the folder that I don't want to copy. I need to get only those few (defined by the sequence).

like image 484
David Oneill Avatar asked Jan 18 '11 20:01

David Oneill


People also ask

How do I SCP multiple files in Linux?

As Jiri mentioned, you can use scp -r user@host:/some/remote/path /some/local/path to copy files recursively. This assumes that there's a single directory containing all of the files you want to transfer (and nothing else).

Can SCP send multiple files?

SCP is a powerful command-line utility that allows you to copy files and directories between remote machines. SCP uses the SSH protocol to securely transfer files between the connected hosts. As a tool, SSH requires you to provide a password for the SSH user or an SSH key for the target host.

How do I SCP an entire directory in Linux?

To copy a directory (and all the files it contains), use scp with the -r option. This tells scp to recursively copy the source directory and its contents. You'll be prompted for your password on the source system ( deathstar.com ). The command won't work unless you enter the correct password.

What does SCP do in bash?

The SCP command or secure copy allows secure transferring of files in between the local host and the remote host or between two remote hosts.


1 Answers

In bash:

scp doneill@server:/mnt/device/folder/numbered_file{16..75}.txt ./
like image 54
Ignacio Vazquez-Abrams Avatar answered Sep 22 '22 13:09

Ignacio Vazquez-Abrams