命令格式
[root@localhost ~]# scp [引數] [原路徑] [目標路徑]
命令功能
scp是 secure copy的縮寫, scp是linux系統下基于ssh登陸進行安全的遠程檔案拷貝命令,linux的scp命令可以在linux服務器之間復制檔案和目錄,
命令引數
-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)的選項,
使用實體
一、從本地服務器復制到遠程服務器:
(1) 復制檔案:
[root@localhost ~]# scp local_file remote_username@remote_ip:remote_folder [root@localhost ~]# scp local_file remote_username@remote_ip:remote_file [root@localhost ~]# scp local_file remote_ip:remote_folder [root@localhost ~]# scp local_file remote_ip:remote_file
第1,2個已指定了用戶名,命令執行后需要輸入用戶密碼,第1個僅指定了遠程的目錄,檔案名字不變,第2個指定了檔案名,
第3,4個沒有指定用戶名,命令執行后需要輸入用戶名和用戶密碼,第3個僅指定了遠程的目錄,檔案名字不變,第4個指定了檔案名,
(2) 復制目錄:
[root@localhost ~]# scp -r local_folder remote_username@remote_ip:remote_folder [root@localhost ~]# scp -r local_folder remote_ip:remote_folder
二、從遠程服務器復制到本地服務器:
(1) 從遠處復制檔案到本地目錄
[root@localhost ~]# scp [email protected]:/opt/soft/nginx-0.5.38.tar.gz /opt/soft/
從192.168.1.68機器上的/opt/soft/的目錄中下載nginx-0.5.38.tar.gz 檔案到本地/opt/soft/目錄中
(2) 從遠處復制目錄到本地目錄
[root@localhost ~]# scp -r [email protected]:/opt/soft/mongodb /opt/soft/
從192.168.1.68機器上的/opt/soft/的目錄中下載mongodb 目錄到本地的/opt/soft/目錄來,
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/100147.html
標籤:Linux
