2

I have 2 virtual machines. The 1st virtual machine is where the source files are stored. The 2nd virtual machine is where my bash script is and it should copy files from source to my 2nd virtual machine.

How can I do this in Bash?

Is it possible to SCP files from 1 virtual machine to a 2nd virtual machine in Bash, when my script is running on the 3rd machine? If so, please show me how to do this.

2
  • A quick read of the scp man page would tell you that only one of the locations can be remote. There are several obvious workarounds. Where's your research? Commented Jan 3, 2013 at 21:31
  • 1
    @Phil: scp [-12346BCEpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 ... [[user@]host2:]file2 I beg to differ. Commented Jan 3, 2013 at 22:04

3 Answers 3

3

It is possible (as long as both hosts are listening on SSH and the first remote host can see the second)! Why don't you give it a try?

scp remote1:/path/to/file remote2:/path/to 

You may need to supply usernames and or passwords for both of these hosts (if your username varies from machine to machine).

If you use agent-based authentication with agent-forwarding enabled, you shouldn't need to provide any passwords (this is my prefered method of working).

Note that this has nothing to do with Bash (or even virtual machines) and should work in any shell.

1
  • 1
    Good explanation -- wish I could +1 for agent forwarding as well Commented Jan 3, 2013 at 22:48
1

Usual way to do this is to ssh into one of the remote machines and issue the scp from there.

#3rd-vm> ssh 2nd-vm #2nd-vm> scp file 1st-vm:~/ 
0

If you need to bridge it through the 3rd machine, you could do it with ssh like this:

ssh remote1 cat file | ssh remote2 'cat > file' 

Or with tar:

ssh remote1 tar cf - path/to/copy | ssh remote2 tar xf - -C path/to/dest 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.