4

The idea is simple, I want to be able to execute the scp command from my system and move files to another computer and vice versa.

My case has a small problem. In order to connect to the end computer I have to first ssh to a host_b and then ssh to host_c.

Long story short, I have to copy all my files to host_b first and then to host_c

This is the scematic:

my_computer -> host_b -> host_c

Since, I have to do this in order to run my code manually every time, it's getting kinda frustrating, So I thought that I should make my own script to automate this process.

Here's my code so far:

#!/usr/bin/expect -f

echo
echo "Move files from your computer to HostC!"
echo

printf 'Username for hostB: '
read -r userB
hostb_addr='hostb.com'

printf 'Username for hostC: '
read -r userC
hostc_addr='hostc.com'

printf 'File you want to move: '
read -r filepath

scp_params='-P 8140'

# connect via scp to hostB
spawn scp $scp_params $filepath $hostb_user@$hostb_addr:~/temp_transfer

interact

The main idea is to get the files from my computer to a temporary folder to hostB, scp them again to hostC and then delete the files from hostB.

I've started trying to make this work but I'm getting a 'spawn command not found'

NOTE: this is actually the first time i've used bash

1
  • @shellter no you can't because of security... You are supposed to do it the way I told you unless you are hardwired in the company's network. So it's kind of a pickle to work from home Commented Aug 24, 2016 at 16:14

1 Answer 1

1

There's already a builtin feature in ssh/scp to do this. You can open a ssh-tunnel from your local position the your hostB, and than to hostC in one command. In scp you can do this with the -o flag.

scp -o ProxyCommand="ssh $hostB nc $hostC 22" $path_to_file $hostC:$path_to_file
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.