5

Suppose I want to rsync file foo.txt on my local machine to file /home/me/somedirectory/bar.txt on a remote computer, and that somedirectory/ doesn't yet exist. How do I do this?

I tried rsync -e ssh -z foo.txt remotemachine:/home/me/somedirectory/bar.txt, but I get a rsync: push_dir#3 "/home/me/somedirectory" failed: No such file or directory (2) error.

(Copying the file without renaming it works, though. That is, this runs fine: rsync -e ssh -z foo.txt remotemachine:/home/me/somedirectory/`)

grautur
  • 29,955
  • 34
  • 93
  • 128
  • I think you can find the same question answered [here](http://stackoverflow.com/questions/1636889/rsync-how-can-i-configure-it-to-create-target-directory-on-server). – frarees Dec 01 '11 at 00:47
  • I tried adding the `--recursive` flag, but I get the same error. – grautur Dec 01 '11 at 01:28

2 Answers2

5

Just put a trailing slash on your target dir. Something like this:

rsync foo.txt remotemachine:somedirectory/

Assuming that "/home/me" is your home dir on the remote machine, there is no need to specify it in the command line. Also, you don't need to clutter up your rsync with the -e unless you just like to do that.

James Parks
  • 51
  • 1
  • 2
1

You can do this process successfully in 2 stepes:-

1] rsync -e ssh -z foo.txt remotemachine:/home/me/somedirectory/ this will copy the foo.txt and create directory somedirectory on destination.

then

2] rsync -e ssh -z --delete-after foo.txt remotemachine:/home/me/somedirectory/bar.txt

and here you can delete foo.txt on destination by using --delete-after option. you can see it's usage from man pages. This option must be used with -r option This serves your purpose.

or if second command doesn't work then use :- rsync -e ssh -z foo.txt remotemachine:/home/me/somedirectory/bar.txt and delete foo.txt manually.

Akshay Patil
  • 954
  • 1
  • 12
  • 28