Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am often in the following situation:

I have two machines, A and B, which are on LANs, and have non-public IP addresses. Machine C is on the same LAN as B, but publicly visible. I would like to copy a file from B to A, so I have to:

  • ssh to C
  • ssh from C to B
  • scp file from B to C
  • scp file from C to A

Given that ssl can do wonderful things with tunnelling displays all the way back from B to A via C transparently, it seems like it should be possible to do the same with files.

Is there a way to use standard ssh/scp to copy from B to A, without having to make a temporary copy on C?

share|improve this question

migrated from stackoverflow.com Oct 20 '09 at 11:56

This question came from our site for professional and enthusiast programmers.

1  
Welcome to Stack Overflow! This site for programming questions, and your question is more suited for superuser.com. I have voted to move it there; after five people vote it will move automatically. –  Greg Hewgill Oct 20 '09 at 8:04
add comment

2 Answers

You want to set up port forwarding. When you SSH from machine A to machine B add a tunnel, i.e. add -L 1234:A:22 when tunnelling to B. Then SSH to machine C and scp the files to B on port 1234 (i.e. add -P 1234 to scp). This will actually route to port 22 on machine A which is the ssh port and hence it'll transfer directly.

I don't have three machines with which to try this right now but I think this should work.

share|improve this answer
add comment

If you can ssh from C to B and scp to A from C, then I think you should be able to use scp directly from C.

(Using aa.aa.aa.aa as A's IP address and bb.bb.bb.bb as B's IP address)

  • ssh into C
  • At the command line on C:

    scp bb.bb.bb.bb:/path/to/file aa.aa.aa.aa:/path/to/destination

share|improve this answer
    
You beat me by 5 seconds. –  NVRAM Oct 20 '09 at 15:20
    
This might not work. If the user can ssh from A -> C, but not from C -> A, the original method described would work, but my solution won't. –  Doug Harris Oct 20 '09 at 17:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.