Scp only a specific folder

directoryscp

Some command line syntax I don't know how to set, am a noob sometimes, sorry is that's obvious

Let's says I have the following path for all my assets :

/var/www/site/system/images/{image_id}/{format}/{file}.{extension}

Inside the {image_id} folder, I have multiple formats (original, medium, thumb, etc…).

I only want to import the /var/www/site/system/images/{image_id}/original folder, and keep the structure locally

scp -r username@server:/var/www/site/system/images/*/original ~/Site/site/system/images

This one does get it all, but all the files end up in the same and unique folder, no structure.

I'd like to keep the structure. Is there something to do for it ?

Best Answer

Use rsync, becasue scp is limited in many ways.

To get you started here is an example:

rsync genja.org:/home/www/*/html/ /tmp/dest/html/ -avin 
host: genja.lan 
receiving incremental file list
created directory /tmp/dest/html
cd+++++++++ ./
>f+++++++++ tabs.html
cd+++++++++ borders/
cd+++++++++ borders/border-radius/
>f+++++++++ borders/border-radius/border-radius.htc
>f+++++++++ borders/border-radius/border-radius.html
cd+++++++++ borders/css-tricks.com/
(...)

The important options are -a and -v if you want to see what is going on. If you add -in then the command will only pretend that it is running, so you can review what will get copied and where.

There is a subtle difference in how trailing slashed are treated. Just make sure you include a trailing slash on both the destination and the source folders to begin with.