目錄
scp 指令的基本用法" >scp 指令的基本用法
使用-v參數顯示 scp 過程的詳細資訊" >使用-v參數顯示 scp 過程的詳細資訊
輸出" >輸出
提供原始檔案的修改時間、存取時間和模式" >提供原始檔案的修改時間、存取時間和模式
使用 -C 參數加快檔案傳輸速度" >使用 -C 參數加快檔案傳輸速度
更改 scp 密码以加密文件" >更改 scp 密码以加密文件
使用 scp 命令限制带宽使用" >使用 scp 命令限制带宽使用
指定要与 scp 一起使用的特定端口" >指定要与 scp 一起使用的特定端口
递归复制目录中的文件" >递归复制目录中的文件
禁用进度表和警告 / 诊断消息" >禁用进度表和警告 / 诊断消息
通过代理使用 scp 复制文件" >通过代理使用 scp 复制文件
选择不同的ssh_config 文件" >选择不同的ssh_config 文件
场景示例" >场景示例
首頁 系統教程 Linux 在 Linux 中傳輸檔案資料夾的 10個 scp 指令

在 Linux 中傳輸檔案資料夾的 10個 scp 指令

Feb 10, 2024 pm 08:30 PM
linux linux教程 linux系統 linux指令 shell腳本 嵌入式linux linux入門 linux學習

scp 指令的基本用法

下面的指令的意思是 把 source_file_name複製到destination_hostusername account下的destination_folder裡。

在 Linux 中传输文件文件夹的 10个 scp 命令

#
> scp source_file_name username@destination_host:destination_folder
登入後複製

複製

有很多參數可以在scp指令中使用。以下是一些在日常操作中可能會用到的參數。

使用-v參數顯示 scp 過程的詳細資訊

#預設的scp指令不帶參數,會在後台默默地複製檔案。使用者只有在過程結束或發生錯誤時才能看到結果。

你可以使用 -v 參數來把偵錯資訊輸出到螢幕上。這樣可以幫助你排查連線、認證和設定方面的問題。

rumenz@local $ scp -v Label.pdf rumenz@192.168.1.110:.
登入後複製
輸出

複製檔案時 scp 顯示進度

Executing: program /usr/bin/ssh host 202.x.x.x, user mrarianto, command scp -v -t .
OpenSSH_6.0p1 Debian-3, OpenSSL 1.0.1c 10 May 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 202.x.x.x [202.x.x.x] port 22.
debug1: Connection established.
debug1: Host '202.x.x.x' is known and matches the RSA host key.
debug1: Found key in /home/pungki/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: Next authentication method: password
rumenz@202.x.x.x's password:
debug1: Authentication succeeded (password).
Authenticated to 202.x.x.x ([202.x.x.x]:22).
Sending file modes: C0770 3760348 Label.pdf
Sink: C0770 3760348 Label.pdf
Label.pdf 100% 3672KB 136.0KB/s 00:27
Transferred: sent 3766304, received 3000 bytes, in 65.2 seconds
Bytes per second: sent 57766.4, received 46.0
debug1: Exit status 0
登入後複製

提供原始檔案的修改時間、存取時間和模式

#-p 參數將幫助你解決這個問題。估計時間和連線速度將出現在螢幕上。

rumenz@local $ scp -p Label.pdf rumenz@192.168.1.110:.
登入後複製
輸出

scp 估計複製大檔案所需的時間

> rumenz@202.x.x.x's password:
Label.pdf 100% 3672KB 126.6KB/s 00:29
登入後複製

使用 -C 參數加快檔案傳輸速度

可以加快檔案傳輸速度的參數之一是 -C 範圍。這 -C 參數將隨時隨地壓縮你的檔案,獨特的是壓縮只發生在網路中。當檔案到達目標伺服器時,它將恢復到壓縮前的原始大小。

> rumenz@local $ scp -pv messages.log rumenz@192.168.1.110:.
登入後複製
輸出

scp 在不壓縮的情況下傳輸檔案

Executing: program /usr/bin/ssh host 202.x.x.x, user mrarianto, command scp -v -p -t .
OpenSSH_6.0p1 Debian-3, OpenSSL 1.0.1c 10 May 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 202.x.x.x [202.x.x.x] port 22.
debug1: Connection established.
debug1: identity file /home/pungki/.ssh/id_rsa type -1
debug1: Found key in /home/pungki/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: Trying private key: /home/pungki/.ssh/id_rsa
debug1: Next authentication method: password
rumenz@202.x.x.x's password:
debug1: Authentication succeeded (password).
Authenticated to 202.x.x.x ([202.x.x.x]:22).
debug1: Sending command: scp -v -p -t .
File mtime 1323853868 atime 1380425711
Sending file timestamps: T1323853868 0 1380425711 0
messages.log 100% 93MB 58.6KB/s 27:05
Transferred: sent 97614832, received 25976 bytes, in 1661.3 seconds
Bytes per second: sent 58758.4, received 15.6
debug1: Exit status 0
登入後複製

-C 允許壓縮

#
rumenz@local $ scp -Cpv messages.log rumenz@192.168.1.110:.
登入後複製
輸出

scp 使用壓縮更快地傳輸檔案

Executing: program /usr/bin/ssh host 202.x.x.x, user mrarianto, command scp -v -p -t .
OpenSSH_6.0p1 Debian-3, OpenSSL 1.0.1c 10 May 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 202.x.x.x [202.x.x.x] port 22.
debug1: Connection established.
debug1: identity file /home/pungki/.ssh/id_rsa type -1
debug1: Host '202.x.x.x' is known and matches the RSA host key.
debug1: Found key in /home/pungki/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: Next authentication method: publickey
debug1: Trying private key: /home/pungki/.ssh/id_rsa
debug1: Next authentication method: password
rumenz@202.x.x.x's password:
debug1: Enabling compression at level 6.
debug1: Authentication succeeded (password).
Authenticated to 202.x.x.x ([202.x.x.x]:22).
debug1: channel 0: new [client-session]
debug1: Sending command: scp -v -p -t .
File mtime 1323853868 atime 1380428748
Sending file timestamps: T1323853868 0 1380428748 0
Sink: T1323853868 0 1380428748 0
Sending file modes: C0600 97517300 messages.log
messages.log 100% 93MB 602.7KB/s 02:38
Transferred: sent 8905840, received 15768 bytes, in 162.5 seconds
Bytes per second: sent 54813.9, received 97.0
debug1: Exit status 0
debug1: compress outgoing: raw data 97571111, compressed 8806191, factor 0.09
debug1: compress incoming: raw data 7885, compressed 3821, factor 0.48
登入後複製

如果你要透過網路複製大量文件,-C 參數將幫助你減少所需的總時間。

压缩方法不适用于所有文件。当源文件已经被压缩时,就没有什么效果了。文件如.zip,.rar,pictures, 和.iso

更改 scp 密码以加密文件

默认情况下scp使用 AES-128 来加密文件。如果你想更改为其他密码对其进行加密,你可以使用 -c 范围。看看这个命令。

rumenz@local $ scp -c 3des Label.pdf rumenz@192.168.1.110:.

rumenz@202.x.x.x's password:
Label.pdf 100% 3672KB 282.5KB/s 00:13
登入後複製

上面的命令告诉scp使用3des algorithm来加密文件。请注意此参数使用 -c不是-C

使用 scp 命令限制带宽使用

另一个可能有用的参数是 -l 范围。这 -l 参数将限制使用的带宽制 。如果你执行自动化脚本来复制大量文件,这将很有用

rumenz@local $ scp -l 400 Label.pdf rumenz@192.168.1.110:.

rumenz@202.x.x.x's password:
Label.pdf 100% 3672KB 50.3KB/s 01:13
登入後複製

scp 默认带宽的单位是Kilobyte/sec(KB/s)。所以如果你想限制你的带宽scp最多只有50 KB/s,你需要将其设置为50 x 8=400.

指定要与 scp 一起使用的特定端口

scp正在使用端口22作为默认端口。但出于安全原因,你可以将端口更改为另一个端口. 例如,我们使用端口2249.

rumenz@local $ scp -P 2249 Label.pdf rumenz@192.168.1.110:.

rumenz@202.x.x.x's password:
Label.pdf 100% 3672KB 262.3KB/s 00:14
登入後複製

递归复制目录中的文件

有时我们需要复制目录和其中的所有文件,目录

rumenz@local $ scp -r documents rumenz@192.168.1.110:.

rumenz@202.x.x.x's password:
Label.pdf 100% 3672KB 282.5KB/s 00:13
scp.txt 100% 10KB 9.8KB/s 00:00
登入後複製

复> 制过程完成后,你将在目标服务器上找到一个名为documents及其所有文件。文件夹documents是自动创建的。

禁用进度表和警告 / 诊断消息

rumenz@local $ scp -q Label.pdf rumenz@192.168.1.110:.

rumenz@202.x.x.x's password:
rumenz@local $
登入後複製

可以看到,输入密码后,没有关于 scp 进程的信息。该过程完成后,你将再次看到提示。

通过代理使用 scp 复制文件

代理服务器通常用于办公环境。scp 本身没有配置代理。当你的环境使用代理时,你必须告诉scp 与代理进行通信。

例如代理地址是10.0.96.6代理端口是8080.代理还实现了用户身份验证。首先,你需要创建 ~/.ssh/config文件

ProxyCommand /usr/bin/corkscrew 10.0.96.6 8080 %h %p ~/.ssh/proxyauth
登入後複製

然后你需要创建文件 ~/.ssh/proxyauth 里面输入。

myusername:mypassword
登入後複製

前提是需要安装corkscrew

$ apt-get install corkscrew
登入後複製

Centos系统可以用yum安装corkscrew

# yum install corkscrew
登入後複製

由于 ~/.ssh/proxyauth 文件包含你的 usernamepassword 以明文格式,请确保该文件只能自己访问。

选择不同的ssh_config 文件

对于经常在公司网络和公共网络之间切换的移动用户来说,总是在scp中更改设置会很痛苦。

场景示例

代理在公司网络中使用,但不在公共网络中使用,并且你定期切换网络。

rumenz@local $ scp -F /home/pungki/proxy_ssh_config Label.pdf

rumenz@192.168.1.110:.
rumenz@202.x.x.x's password:
Label.pdf 100% 3672KB 282.5KB/s 00:13
登入後複製

默认情况下 ssh_config 每个用户的文件将被放置在 ~/.ssh/config。创建一个特定的 ssh_config 具有代理兼容性的文件将更容易在网络之间切换。

当你在公司网络,你可以使用 -F 范围。当你在公共网络上时,你可以不用-F参数。

以上是在 Linux 中傳輸檔案資料夾的 10個 scp 指令的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

vscode需要什麼電腦配置 vscode需要什麼電腦配置 Apr 15, 2025 pm 09:48 PM

VS Code 系統要求:操作系統:Windows 10 及以上、macOS 10.12 及以上、Linux 發行版處理器:最低 1.6 GHz,推薦 2.0 GHz 及以上內存:最低 512 MB,推薦 4 GB 及以上存儲空間:最低 250 MB,推薦 1 GB 及以上其他要求:穩定網絡連接,Xorg/Wayland(Linux)

Linux體系結構:揭示5個基本組件 Linux體系結構:揭示5個基本組件 Apr 20, 2025 am 12:04 AM

Linux系統的五個基本組件是:1.內核,2.系統庫,3.系統實用程序,4.圖形用戶界面,5.應用程序。內核管理硬件資源,系統庫提供預編譯函數,系統實用程序用於系統管理,GUI提供可視化交互,應用程序利用這些組件實現功能。

notepad怎麼運行java代碼 notepad怎麼運行java代碼 Apr 16, 2025 pm 07:39 PM

雖然 Notepad 無法直接運行 Java 代碼,但可以通過借助其他工具實現:使用命令行編譯器 (javac) 編譯代碼,生成字節碼文件 (filename.class)。使用 Java 解釋器 (java) 解釋字節碼,執行代碼並輸出結果。

vscode終端使用教程 vscode終端使用教程 Apr 15, 2025 pm 10:09 PM

vscode 內置終端是一個開發工具,允許在編輯器內運行命令和腳本,以簡化開發流程。如何使用 vscode 終端:通過快捷鍵 (Ctrl/Cmd ) 打開終端。輸入命令或運行腳本。使用熱鍵 (如 Ctrl L 清除終端)。更改工作目錄 (如 cd 命令)。高級功能包括調試模式、代碼片段自動補全和交互式命令歷史。

git怎麼查看倉庫地址 git怎麼查看倉庫地址 Apr 17, 2025 pm 01:54 PM

要查看 Git 倉庫地址,請執行以下步驟:1. 打開命令行並導航到倉庫目錄;2. 運行 "git remote -v" 命令;3. 查看輸出中的倉庫名稱及其相應的地址。

vscode 無法安裝擴展 vscode 無法安裝擴展 Apr 15, 2025 pm 07:18 PM

VS Code擴展安裝失敗的原因可能包括:網絡不穩定、權限不足、系統兼容性問題、VS Code版本過舊、殺毒軟件或防火牆干擾。通過檢查網絡連接、權限、日誌文件、更新VS Code、禁用安全軟件以及重啟VS Code或計算機,可以逐步排查和解決問題。

vscode在哪寫代碼 vscode在哪寫代碼 Apr 15, 2025 pm 09:54 PM

在 Visual Studio Code(VSCode)中編寫代碼簡單易行,只需安裝 VSCode、創建項目、選擇語言、創建文件、編寫代碼、保存並運行即可。 VSCode 的優點包括跨平台、免費開源、強大功能、擴展豐富,以及輕量快速。

vscode 可以用於 mac 嗎 vscode 可以用於 mac 嗎 Apr 15, 2025 pm 07:36 PM

VS Code 可以在 Mac 上使用。它具有強大的擴展功能、Git 集成、終端和調試器,同時還提供了豐富的設置選項。但是,對於特別大型項目或專業性較強的開發,VS Code 可能會有性能或功能限制。

See all articles