7

Let’s say we have three machines: A, B and C.

  • Machine A can't reach machine B from any network, so I can't send files between both.
  • But both A and B can be reached from C (my machine).

Today I have to copy a huge file from A to B.

Currently I would need to copy it first from A to C and then from C to B. Is there a way to connect or pipe the scp to stream the incoming data to the target machine without need to save in the middle?

0

2 Answers 2

16

man scp writes (with my emphasis)

-3 Copies between two remote hosts are transferred through the local host. Without this option the data is copied directly between the two remote hosts. [...]

So what you need is a copy command that routes via your local system (I almost always include -p, to preserve timestamps and permissions, so I've done that here too):

scp -3p serverA:path/to/file(s) serverB:/path/to/destination 

Very recent versions of scp have -3 enabled by default since 9 August 2021, and to disable it one must now specify -R. Using this third party copy feature will disable prompts for passphrases and passwords as scp cannot ask for them for both hosts.

0
1

scp user1@A:from_file user2@B:to_file should do the trick. Read man scp.

6
  • 1
    It expands to ssh user1@A "scp from_file user2@B:to_file" Commented Aug 26, 2021 at 19:24
  • 2
    @Vlad I think your tip will make A send file to B but as I said there is no network between both Commented Aug 27, 2021 at 2:50
  • @MagnoC I know, this tip expands the answer of waltinator. Commented Aug 27, 2021 at 7:20
  • The whole point of the question seems to be that this method doesn't work. Commented Aug 27, 2021 at 13:54
  • 2
    However, as mentioned in the other answer, recent versions of scp use -3 mode by default, in which case this should work. Commented Aug 27, 2021 at 13:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.