1

I'm using Ubuntu Linux 12.04 LTS on my machine.

There are two remote servers viz.

  • 64.211.219.95
  • 42.11.37.153

I can log in to both servers using ssh command. Both the servers have username root.

Now I want to copy all the files and folders present in folder '/var/www/' from server 64.211.219.95 to the folder '/var/www/project_dir/' on server '42.11.37.153' remotely i.e. using scp command.

How should I do it? What should be the exact command without any syntactical error I've to use to make this operation working?

Please somebody help me.

Thanks in advance.

PHPLover
  • 1
  • 51
  • 158
  • 311
  • As I understand both directories are on the same server, thus [you don't need scp](http://stackoverflow.com/questions/305035/how-to-use-ssh-to-run-shell-script-on-a-remote-machine). – Emilien Dec 02 '15 at 10:33
  • @Emilien:No, both directories are on different servers. – PHPLover Dec 02 '15 at 10:41

3 Answers3

2

I presume that your problem is with specifying a wildcard. You can avoid this difficulty using a recursive copy from a directory with a trailing slash, vis:

scp -r root@64.211.219.95:/var/www/ root@42.11.37.153:/var/www/project_dir

The scp command can be run from any server you like, not restricted to the source or destination machine.

Neil Masson
  • 2,609
  • 1
  • 15
  • 23
  • Both directories are on different servers. Could you please modify your answer accordingly. Also let me know on which server I've to get login to run the scp command. – PHPLover Dec 02 '15 at 10:42
  • To which server I should log in using ssh and run the command you given? – PHPLover Dec 02 '15 at 10:50
  • You can run this from any server - one of the two you have mentioned or any other you like. – Neil Masson Dec 02 '15 at 10:54
  • Don't I need to use /var/www/* to copy all contents present in folder www? – PHPLover Dec 02 '15 at 10:54
  • I would be very careful about using `*` as it is would need to be passed to the remote machine before expansion. The `-r` sidesteps the problem. Be careful to append `/` to the source directory to avoid copying the directory itself. – Neil Masson Dec 02 '15 at 10:58
1

Login at server 64.211.219.95 and use:

scp -r /var/www root@42.11.37.153:/var/www/project_dir
anand mishra
  • 900
  • 1
  • 11
  • 30
1

In some cases, depending on your solution and infrastructure, you probably would like to synchronize your source_dir with remote_dir, still using SSH secure and fast protocol. This way you don't need to copy WHOLE package, but only what is necessary(changes).

In this case, what you want is rsync:

rsync -Cravgtzp --delete --exclude="*.gz" -e ssh user@source_host:source_dir/ user@remote_host:remote_dir/ >> /tmp/logfile.log

Note:

--delete is used when you want to delete files within remote_dir when they have been deleted within source_dir.

--exclude is used when you don't have interest in copying those files (supposing *.gz are temporary files fix example)..

whoan
  • 8,143
  • 4
  • 39
  • 48
Hudson Santos
  • 155
  • 10