One can use the scp command to securely copy files between network hosts. It uses ssh for data transfer and authentication. Typical syntax is:
scp file1 user@host:/path/to/dest/ scp -r /path/to/source/ user@host:/path/to/dest/
I don't think you can filter or exclude files when using the scp command. However, there is a good workaround to exclude the file and copy it securely using ssh. This page explains how to filter or exclude files when copying a directory recursively using scp.
The syntax is:
rsync av -e ssh --exclude='*.out' /path/to/source/ user@hostB:/path/to/dest/
here:
In this example, all files are copied recursively from the ~/virt/ directory, but all *.new files are excluded:
$ rsync -av -e ssh --exclude='*.new' ~/virt/ root@centos7:/tmp
Example output:
Scp exclude files but using rsync exclude command
If rsync is not found on the remote server, the rsync command will fail. In this case, try using the following scp command, which uses bash shell pattern matching in the current directory (it does not work with the -r option):
$ ls
Example output:
centos71.log centos71.qcow2 centos71.qcow2.new centos71.v2.qcow2.new meta-data user-data
Copy everything in the current directory except .new:
$ shopt -s extglob $ scp !(*.new) root@centos7:/tmp/
Example output:
centos71.log 100 % 4262 1.3MB/s 00:00 centos71.qcow2 100 % 836MB 32.7MB/s 00: 25 meta-data 100 % 47 18.5KB/s 00:00 user-data 100 % 1543 569.7KB/s 00:00
For more information, see the following man pages:
$ rsync -av -e ssh --exclude='*.new' ~/virt/ root@centos7:/tmp
The above is the detailed content of SCP usage tips-recursively exclude files. For more information, please follow other related articles on the PHP Chinese website!