How to scp from remote server multiple files

What is Secure Copy?

scp allows files to be copied to, from, or between different hosts. It uses ssh for data transfer and provides the same authentication and same level of security as ssh.

Basic syntax of SCP

scp source_file_name username@destination_host:destination_folder

“copy source_file_name” into “destination_folder” at “destination_host” using “username account”.

How to copy single file
$scp -p username@hostname:/u01/local/oracle/db_01/backup/<FileName> .

 

How to copy multiple files
To use wildcard on the remote host, we must delimit the wildcards with backslash (\)
example
$ scp -p username@hostname:/u01/local/oracle/db_01/backup/\*.dmp .

The above command will pass “*.dmp”

How to copy Entire folder

$ scp -p username@hostname:/u01/local/oracle/db_01/backup/\* .

Examples

1.1 Copy the file “foobar.txt” from a remote host to the local host

$ scp your_username@remotehost.edu:foobar.txt /some/local/directory

1.2 Copy the file “foobar.txt” from the local host to a remote host

$ scp foobar.txt your_username@remotehost.edu:/some/remote/directory

1.3 Copy the directory “foo” from the local host to a remote host’s directory “bar”

$ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar

1.4 Copy the file “foobar.txt” from remote host “rh1.edu” to remote host “rh2.edu”

$ scp your_username@rh1.edu:/some/remote/directory/foobar.txt \
your_username@rh2.edu:/some/remote/directory/

1.5 Copying the files “foo.txt” and “bar.txt” from the local host to your home directory on the remote host

$ scp foo.txt bar.txt your_username@remotehost.edu:~

1.6 Copy the file “foobar.txt” from the local host to a remote host using port 2264

$ scp -P 2264 foobar.txt your_username@remotehost.edu:/some/remote/directory
1.7 Copy multiple files from the remote host to your current directory on the local host

$ scp your_username@remotehost.edu:/some/remote/directory/\{a,b,c\} .

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.