LoginSignup
37
26

More than 5 years have passed since last update.

scpでリモートサーバーからリモートサーバーにファイル転送

Posted at

やりたいこと

[localhost] ┬────ssh接続可能────────[remotehost1] 
            │                           │
            │                           ×ここはつながってない
            │                           │
            └────ssh接続可能─────────[remotehost2]

上記のような環境で、localhostから、remotehost1のファイルをremotehost2にできれば ワンコマンド でコピーする

答え

結論から言うと、-3 オプションをつけることで可能となります。

scp -3 remotehost1:text.txt remotehost2:

解説

興味のある方のみどうぞ。。
大したことではなく、scpの仕様の問題です。

単純にやろうとすると、以下を書きたくなります。

scp remotehost1:text.txt remotehost2:

→これは、失敗します。

ssh: connect to host [remotehost2のIP] port 22: Connection timed out
lost connection
Connection [remotehost1のIP] closed.

なぜなら、上記のような書き方をした場合、

[localhost]───────ssh接続可能────────[remotehost1]──────────ssh接続可能──────────[remotehost2]

であることが条件となります。
つまり、実際のファイル転送は、remotehost1が行うようです。

37
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
37
26