Scp

如何使用 scp 將目錄中的所有文件複製到遠端目錄?

  • January 20, 2022

My goal is copy only all files from ~/local_dir to user@host.com /var/www/html/target_dir using scp and do not create local_dir category in local_dir.

/var/www/html/target_dir/files..

but not

/var/www/html/target_dir/local_dir/files.. when use -r parameter

scp has the -r argument. So, try using:

$ scp -r ~/local_dir user@host.com:/var/www/html/target_dir

The -r argument works just like the -r arg in cp, it will transfer your entire folder and all the files and subdirectories inside.

If your goal is to transfer all files from local_dir the * wildcard does the trick:

$ scp ~/local_dir/* user@host.com:/var/www/html/target_dir

The -r option means “recursively”, so you must write it when you’re trying to transfer an entire directory or several directories.

From man scp:

-r 
Recursively copy entire directories. Note that scp follows symbolic links encountered in the tree traversal.

所以如果你在裡面有子目錄local_dir,最後一個例子只會傳輸文件,但是如果你設置-r選項,它會傳輸文件和目錄。

引用自:https://unix.stackexchange.com/questions/232946