45

Would I be able to use rsync as such:

rsync -e ssh root@remote.com:/path/to/file:/path/to/second/file/ /local/directory/

or would i have to do something else?

FilBot3
  • 3,460
  • 6
  • 33
  • 55

2 Answers2

62

Directly from the rsync man page:

The syntax for requesting multiple files from a remote host is done
by specifying additional remote-host args in the same style as the 
first, or with the hostname omitted.  For instance, all these work:

    rsync -av host:file1 :file2 host:file{3,4} /dest/
    rsync -av host::modname/file{1,2} host::modname/file3 /dest/
    rsync -av host::modname/file1 ::modname/file{3,4}

This means your example should have a space added before the second path:

rsync -e ssh root@remote.com:/path/to/file :/path/to/second/file/ /local/directory/

I'd suggest you first try it with the -n or --dry-run option, so you see what will be done, before the copy (and possible deletions) are actually performed.

Alan W. Smith
  • 24,647
  • 4
  • 70
  • 96
Lætitia
  • 1,388
  • 1
  • 20
  • 30
  • I didn't think about this when I asked my question, but the dry run worked. Now, if I were to specify from multiple directories on my source, would I specify multiple destination directories as the same? Or is there a way to copy the whole folder and its contents to the destination? When I did the rsync command the first time, it just copied the contents of the file. In the man page it says something about --dirs or using -r. Or would it matter if I left the / on the end of the source file name? – FilBot3 Apr 05 '13 at 13:29
  • If you want to copy directories, you just have to give the path to a directory as source. If you're using `-r` (or `-a` as in the man page example), you'll then be copying the whole source directory into your destination, preserving the structure of this directory. – Lætitia Apr 07 '13 at 20:29
  • 27
    For posterity: this is apparently not true for old versions of rsync, such as the rsync 2.6.9 that seems to come with OSX 10.9; that version wants you to do `rsync -av host:'file1 file2'`, which gets awkward when filenames also have spaces in them. (Luckily, homebrew has a more recent version.) – Danica Dec 28 '13 at 22:16
  • I tried using a syntax like the `file{3,4}` curly bracket syntax on their example, and it didn't work. It could be my non-bash shell though. – thomasrutter Nov 02 '17 at 23:15
  • 1
    For even more post- posterity: rsync that comes built in with macOS 10.12 *still* uses the old syntax mentioned by @Dougal. Note that rsync 3 was released almost exactly 10 years before my comment here, whereas macOS uses the one released 12 years prior to this comment – JDS Feb 08 '18 at 19:03
  • And still more post-posterity: MacOS Catalina, 10.15.3 ***still*** ships with `rsync version 2.6.9`. –  Mar 02 '20 at 06:53
5

just an actual example of @tonin. Download specific directories from live server

rsync -av root@123.124.137.147:/var/www/html/cls  \
:/var/www/html/index.php \
:/var/www/html/header.inc \
:/var/www/html/version.inc.php \
:/var/www/html/style.css \
:/var/www/html/accounts \
:/var/www/html/admin \
:/var/www/html/api \
:/var/www/html/config \
:/var/www/html/main \
:/var/www/html/reports .
zzapper
  • 4,743
  • 5
  • 48
  • 45