Samstag, 7. November 2015

scp files from A to C or from C to A via intermediate host B



I have access to three different machines A, B and C like:A to BB to AB to CC to Bbut not from A to C and not from C to A because A and C are on a different network.
In order to transfer files from A to C or from C to A do the following:
ssh -fN -L 4567:C:22 username_of_B@B
and then to transfer a directory from C to A:
scp -r -P 4567 localhost:directory_on_C path_on_A_where_to_put_the_directory
to transfer a directory from A to C:scp -r -P 4567 directory_on_A_which_is_to_transfer localhost:path_on_C_where_to_put
and for transfering files:to transfer a file from C to A:
scp -P 4567 localhost:file_to_transfer_on_C path_on_A_where_to_put_the_file
to transfer a file from A to C:
scp -P 4567 file_on_A_which_to_transfer localhost:path_on_C_where_to_put_the_file


Even better is this command to rsync files from computer A to computer C (or vice versa)via intermediate computer B:
rsync -av -e 'ssh -o "ProxyCommand ssh username_at_computer_B@IP_of_computer_B exec nc %h %p 2greater/dev/null"' username_at_computer_C@IP_of_computer_C:directory_on_C_to_sync/* directory_on_A_to_sync/



the word "greater" in the line above has to be replaced with the greater symbol of the keyboard. I can not do it here because while saving it is being replaced with >