使用scp傳輸檔案

2021-08-20 23:02:47 字數 2630 閱讀 5253

scpsecure copy的縮寫,主要用於伺服器檔案傳輸,是linux系統下基於ssh登陸進行安全的遠端檔案拷貝命令。

命令格式

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)的選項。

使用示例

1.從本地伺服器複製到遠端伺服器

## local_file      本地檔名

## local_folder 本地資料夾

## remote_username 遠端伺服器使用者名稱[選填](不填預設與本地同使用者名稱)

## remote_ip 遠端伺服器ip

## remote_file 遠端伺服器檔名(重新命名)

## remote_folder 遠端伺服器資料夾

## -r 資料夾遞迴迴圈

//檔案

scp local_file [remote_username@]remote_ip:remote_file/remote_folder

//資料夾

scp -r local_folder [remote_username@]remote_ip:remote_folder

example

scp /xx/xx/1.php [email protected]

:/xx/xx/

scp /xx/xx/1.php [email protected]

:/xx/xx/

2.php

scp /xx/xx/1.php 127.0.0.1

:/xx/xx/

scp /xx/xx/1.php 127.0.0.1

:/xx/xx/

2.php

scp -r /xx/xx/ [email protected]

:/xx/xx/

scp -r /xx/xx/ 127.0.0.1

:/xx/xx/

2.從遠端伺服器複製到本地伺服器
## local_file      本地檔名

## local_folder 本地資料夾

## remote_username 遠端伺服器使用者名稱[選填](不填預設與本地同使用者名稱)

## remote_ip 遠端伺服器ip

## remote_file 遠端伺服器檔名(重新命名)

## remote_folder 遠端伺服器資料夾

## -r 資料夾遞迴迴圈

//檔案

scp [remote_username@]remote_ip:remote_file remote_file/local_folder

//資料夾

scp -r [remote_username@]remote_ip:remote_folder local_folder

example

scp [email protected]

:/xx/xx/

1.php /xx/xx/2.php

scp [email protected]

:/xx/xx/

1.php /xx/xx/

scp 127.0.0.1

:/xx/xx/

1.php /xx/xx/2.php

scp 127.0.0.1

:/xx/xx/

1.php /xx/xx/

scp -r [email protected]

:/xx/xx/ /xx/xx/

scp -r 127.0.0.1

:/xx/xx/ /xx/xx/

利用ssh傳輸檔案 scp

url mac參考 scp出現ssh port 22 connection refused 在linux下一般用scp這個命令來通過ssh傳輸檔案。2 上傳本地檔案到伺服器 scp path filename username servername path 例如scp var www test.p...

Linux 檔案傳輸 SCP

在linux下一般用scp這個命令來通過ssh傳輸檔案。2 上傳本地檔案到伺服器 scp path filename username servername path 例如scp var www test.php root 192.168.0.101 var www 把本機 var www 目錄下的...

scp免密傳輸檔案

scp 命令 例如 把本地 backup a.txt檔案傳輸至192.168.80.128伺服器,賬號root 目錄為 backup scp backup a.txt root 192.168.80.128 backup 反之把192.168.80.128伺服器下backup a.txt檔案傳輸至本...