scp -3:直接對兩個 remote host 複製檔案

剛剛找資料才發現的,scp 指令早就可以針對兩個遠端複製檔案了:「scp from one remote server to another remote server」。

可以加上 -3,像是這樣:

scp -3 src:/foo/bar/a.zip dst:/tmp/

不過依照說明可以不用加,因為這是 default 值:

Copies between two remote hosts are transferred through the local host. Without this option the data is copied directly between the two remote hosts. Note that, when using the legacy SCP protocol (via the -O flag), this option selects batch mode for the second host as scp cannot ask for passwords or passphrases for both hosts. This mode is the default.

看了 Stack Exchange 上的回答日期,是 2014 年十月回的,所以至少 Ubuntu 16.04 就有這個功能了?(沒有去查這個功能多早...)

之前一直都是查怎麼用 rsync 搬,然後發現做不到所以都還是傻傻的透過 jump server 轉運檔案,沒想到隔壁棚早就給了解法...

這樣有些情境搬檔案就簡單多了...

One thought on “scp -3:直接對兩個 remote host 複製檔案”

  1. gugod says:

    從 scp -v foo:test.txt bar:test.txt 的紀錄中載入 host key 的紀錄來判斷,無論有沒有加再 -3 上去,連往 bar 的 connection 都是源自本地端。如果加 -R,連往 bar 的 connection 則是源自 foo。

    (OpenSSH_9.0p1, OpenSSL 3.0.9 30 May 2023)

Leave a Reply

Your email address will not be published. Required fields are marked *