功能:
scp是 secure copy的縮寫, scp是linux系統下基於ssh登陸進行安全的遠程文件拷貝命令。linux的scp命令可以在linux服務器之間復制文件和目錄。
語法:
scp [參數] [原路徑] [目標路徑]
參數:
-1 強制scp命令使用協議ssh1
-2 強制scp命令使用協議ssh2
-4 強制scp命令只使用IPv4尋址
-6 強制scp命令只使用IPv6尋址
-B 使用批處理模式(傳輸過程中不詢問傳輸口令或短語)
-C 允許壓縮。(將-C標志傳遞給ssh,從而打開壓縮功能)
-p 保留原文件的修改時間,訪問時間和訪問權限。
-q 不顯示傳輸進度條。
-r 遞歸復制整個目錄。
-v 詳細方式顯示輸出。scp和ssh(1)會顯示出整個過程的調試信息。這些信息用於調試連接,驗證和配置問題。
-c cipher 以cipher將數據傳輸進行加密,這個選項將直接傳遞給ssh。
-F ssh_config 指定一個替代的ssh配置文件,此參數直接傳遞給ssh。
-i identity_file 從指定文件中讀取傳輸時使用的密鑰文件,此參數直接傳遞給ssh。
-l limit 限定用戶所能使用的帶寬,以Kbit/s為單位。
-o ssh_option 如果習慣於使用ssh_config(5)中的參數傳遞方式,
-P port 注意是大寫的P, port是指定數據傳輸用到的端口號
-S program 指定加密傳輸時所使用的程序。此程序必須能夠理解ssh(1)的選項。
示例一:
從本地傳文件夾到遠端。
命令格式:scp local_file remote_username@remote_ip:remote_folder
把本地當前目錄下mcu文件夾復制到10.84.2.104服務器的/opt/aaa目錄下。
1 [root@localhost opt]# ll 2 total 192560 3 drwx------ 2 root root 16384 Aug 29 2016 lost+found 4 drwxr-xr-x 9 root root 4096 Sep 19 03:33 mcu 5 -rw-r--r-- 1 root root 197154017 Oct 23 09:34 mcu.zip
6 [root@localhost opt]# scp -P 22223 -r mcu root@10.84.2.104:/opt/aaa
7 The authenticity of host '[10.84.2.104]:22223 ([10.84.2.104]:22223)' can't be established. 8 ECDSA key fingerprint is 92:7e:86:77:fb:8e:a8:fc:e2:b6:6c:44:8c:5b:82:e7. 9 Are you sure you want to continue connecting (yes/no)? yes 10 Warning: Permanently added '[10.84.2.104]:22223' (ECDSA) to the list of known hosts. 11 root@10.84.2.104's password:
示例二:
從遠端復制到本地
命令格式:scp remote_username@remote_ip:remote_folder local_file
把10.84.2.104服務器的/opt/aaa目錄下的mcu.zip文件復制到本地/opt/目錄下。
1 [root@localhost opt]# ll 2 total 20 3 drwx------ 2 root root 16384 Aug 29 2016 lost+found 4 drwxr-xr-x 9 root root 4096 Sep 19 03:33 mcu 5 [root@localhost opt]# 6 [root@localhost opt]#
7 [root@localhost opt]# scp -P 22223 root@10.84.2.104:/opt/hpl/mcu.zip /opt/ 8 root@10.84.2.104's password: 9 Permission denied, please try again. 10 root@10.84.2.104's password: 11 mcu.zip 100% 188MB 94.0MB/s 00:02 12 [root@localhost opt]# ll 13 total 192556 14 drwx------ 2 root root 16384 Aug 29 2016 lost+found 15 drwxr-xr-x 9 root root 4096 Sep 19 03:33 mcu 16 -rw-r--r-- 1 root root 197154017 Oct 23 09:47 mcu.zip