0

I have a PC-1 in my home and need to transfer files back and forth to my PC-2 at my University.

The problem is that PC-2 has only access to local network.

So, in order to access it from home I have to ssh to the University server and only then ssh to PC-2.

I know that scp can transfer files between two PCs, but did not find anything in documentation for when there is a server in the middle.

Can it be done with scp or other tool?

dvhh
  • 4,724
  • 27
  • 33
thyyrr
  • 29
  • 4
  • 4
    possible duplicate of [How to scp with a second remote host](http://stackoverflow.com/questions/9139417/how-to-scp-with-a-second-remote-host) – dvhh Aug 26 '15 at 03:24
  • 1
    And [off-topic](http://stackoverflow.com/help/on-topic) here anyway. – Martin Prikryl Aug 26 '15 at 05:25

2 Answers2

2

Alternative answer if the ssh tunnel is disabled on the server side :

  • PC-2 to PC-1

    ssh university-server 'ssh PC-2 "cat remotefile"' > localfile

  • PC-1 to PC-2

    ssh university-server 'ssh PC-2 "cat > remotefile"' < localfile

Explanation :
You are asking university-server to ssh to PC-2 with the specified command ( in this case cat) and using pipe redirection to write or read from local files

PS: Modified the answer according to working correction in the comment

dvhh
  • 4,724
  • 27
  • 33
  • `PC-2` to `PC-1` works like a charm, thanks. but not the other way around – thyyrr Aug 26 '15 at 05:12
  • 1
    the problem was missing quotes, this works `ssh university-server 'ssh PC-2 "cat > remotefile"' < localfile` – thyyrr Aug 26 '15 at 05:25
1

You can use an ssh tunnel, to connect to PC-2 from PC-1 using university-server as an intermediate.

  1. Establish the tunnel

    ssh -f -N university-server -L 2222:PC-02:22

    the tunnel will be kept in background until the ssh process is killed

  2. scp file transfert

    • scp -P 2222 user@localhost:file .
    • scp -P 2222 file user@localhost:path
dvhh
  • 4,724
  • 27
  • 33
  • I can estabilish the tunnel, but when I run scp it hangs. Stays as if it processing, but no response after more than a minute. – thyyrr Aug 26 '15 at 03:44
  • could you test the tunnel by using `ssh -p 2222 user@localhost`, or could you ping `PC-2` from `university-server` ? – dvhh Aug 26 '15 at 03:50
  • The `ssh` test shows this message **channel 2: open failed: administratively prohibited: open failed \ ssh_exchange_identification: Connection closed by remote host** – thyyrr Aug 26 '15 at 03:58
  • also, unfortunately depending on the ssh server configuration, ssh tunneling might be disabled by the administrator. – dvhh Aug 26 '15 at 04:19
  • no, when I try the `ssh -p 2222 user@localhost` I get that message. but what I can do is ssh to `university-server` and then ssh to `PC-2` – thyyrr Aug 26 '15 at 04:21