I have a folder that contains files for a static website like:

/site/index.html
/site/css/css.css
/site/js/js.js
/site/images/...

If I update something on my laptop, I want a single command to send the files off to my ubuntu server. I don't want to setup FTP on it if I don't have too, wondering if scp would be able to handle this?

link|improve this question

51% accept rate
feedback

3 Answers

up vote 4 down vote accepted

The command scp -r source user@target:dest will walk all subdirectories of source and copy them.

However if you are only making updates, not re-creating the whole thing, you will probably find things move along faster if you use rsync over ssh instead of scp. Probably something like

rsync -av -e ssh source user@target:dest

...to get started. If you are doing this across a LAN, I would personally use the options -avW instead for rsync.

Rsync also gives you the ability to duplicate deletions in your source; so if you remove a file from your tree, you can run rsync as above, and include the flag --delete and it will remove the same file from the destination side.

link|improve this answer
feedback

scp has a recursive flag that will do what you want. scp -r /base/directory user@server:/to/location

from man scp

-r      Recursively copy entire directories.  Note that scp follows symbolic
          links encountered in the tree traversal.
link|improve this answer
feedback

scp -r and rsync -r are the most reliable ways to get what you want, as others have noted.

You can also use sshfs to 'mount' it as if it were a local drive: sshfs user@host:/site /mnt/mountpoint

(However you're probably better off working locally and deploying with rsync. Just another tool to be aware of.)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.