thyyrr
thyyrr

Reputation: 29

How to transfer files between two computers with a server in the middle?

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?

Upvotes: 0

Views: 2028

Answers (2)

dvhh
dvhh

Reputation: 4750

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

Upvotes: 2

dvhh
dvhh

Reputation: 4750

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

Upvotes: 1

Related Questions