Saturday, 1 October 2011

SCP: How to transfer multiple files

Kudos goes to Joyce Babu, whose blog can be found at:

Copying from her article

When you have to copy multiple files to your remote server, the syntax is similar to the cp command.
scp file1.sql
Where file1.sql and are the files to be copied, joyce is the username, is the hostname and ~/upload is the destination directory on the remote server.
In order to download multiple files from the remote server, the command to be used is
scp"file1.log file2.log" ~/logs
Where file1.log and file2.log are the files to be downloaded and ~/logs is the destination directory on the local server. Notice the quotes around the filenames. This ensures that the filenames list is not parsed by the local shell and is passed to the remote shell. Similarly, when you want to download files using wildcards (*.php, files_?.log etc), you should enclose the name within quotes to ensure that the expansion is done by the remote server.
The -r option can be used to copy directories recursively.
scp -r ~/logs
This may not be a lifesaver tip and the time gained by this method may be small. After all, when a large number of files are to be transferred, I use FTP or tar my files and copy it. But at times when things go wrong, even this small gain can help.

1 comment:

  1. you can also use something like this to copy multiple files

    scp file*.sh