linux服務器之間文件傳輸scp

linux scp 

Linux scp命令用於Linux之間複製文件和目錄。

scp是 secure copy的縮寫, scp是linux系統下基於ssh登陸進行安全的遠程文件拷貝命令。

語法:

scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user@]host1:]file1 [...] [[user@]host2:]file2

簡單語法:

scp [參數] file1 file2

參數說明:

  • -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、從本地複製到遠程

複製文件

scp local_file remote_user@remote_ip:remote_folder 
或者 
scp local_file remote_user@remote_ip:remote_file 
或者 
scp local_file remote_ip:remote_folder 
或者 
scp local_file remote_ip:remote_file 

案例:

#將本地superl1的test.txt文件傳輸到superl2服務器/home/superl2/test/文件夾下,需輸入密碼
scp /home/superl1/test/test.txt [email protected]:/home/superl2/test/ 

#將本地superl1的test.txt文件傳輸到superl2服務器/home/superl2/test/test2.txt(更換名稱),需輸入密碼
scp /home/superl1/test/test.txt [email protected]:/home/superl2/test/test2.txt

#將本地superl1的test.txt文件傳輸到superl2服務器/home/superl2/test/文件夾下,需輸入用戶名、密碼
scp /home/superl1/test/test.txt 192.168.27.128:/home/superl2/test/

#將本地superl1的test.txt文件傳輸到superl2服務器/home/superl2/test/文件夾下,需輸入用戶名、密碼
scp /home/superl1/test/test.txt 192.168.27.128:/home/superl2/test/test2.txt 

複製文件夾

scp -r local_folder remote_user@remote_ip:remote_folder 
或者 
scp -r local_folder remote_ip:remote_folder 

案例:

#將本地的test文件夾複製到superl2服務器上/home/superl2/test/ ,需要輸入用戶密碼
scp -r /home/superl1/test/ [email protected]:/home/superl2/test/ 


#將本地的test文件夾複製到superl2服務器上/home/superl2/test/ ,需要輸入用戶和密碼
scp -r /home/superl1/test/ 168.192.27.128:/home/superl2/test/ 

2、從遠程複製到本地

將file1和file2位置替換一下即可

#將superl2服務器上覆制到/home/superl2/test/本地的test文件夾 ,需要輸入用戶密碼
scp -r [email protected]:/home/superl2/test/ /home/superl1/test/  


#將superl2服務器上/home/superl2/test/複製到本地的test文件夾 ,需要輸入用戶和密碼
scp -r 168.192.27.128:/home/superl2/test/  /home/superl1/test/ 

如果設定了防火牆,例如端口爲1234

#scp 命令使用端口號 1234
scp -P 1234 -r [email protected]:/home/superl2/test/ /home/superl1/test/

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章