Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Supposed local folder as below:

  1. How to exclude .hiddenfolder to be transfer when executing "scp -r test user@ip:/"?

  2. How to include *.htm files only and transfer them to corresponding subfolder on remote server?

  3. Any other commands can do this job more easily?

share|improve this question
up vote 5 down vote accepted

I don't think scp alone can do what you ask. You should investigate rsync instead.

I use it for backups with a filter to exclude files with names that don't work on NTFS volumes

# the exclude is to filter out files with invalid names on NTFS
/usr/bin/rsync -rgqoxD --delete --exclude='*[:\?]*' /home/andrewr/src /filer001/syncd/src

you can also pass it the name of a file that contains the files to exclude (--exclude-from=file)

Edit: Here's a sample command line that works for your example:

cd src; find . -type f -name "*.htm" | rsync -av --files-from=- . host:dir
share|improve this answer
This is definitely the best way to do it. rsync also uses SSH as a transport, so is more or less equivalent to using scp. – Kamil Kisiel Oct 27 '09 at 4:45

If you already have pre-shared ssh keys, you could first create all the remote directories in the following way:

# get all directories in this tree
for DIR in `find . -type d`
        # create remote directory
        ssh user@host mkdir -p /path/to/start/$DIR
        # copy *only* *.htm files
        scp $DIR/*.htm user@host:/path/to/start/$DIR

I think that's about what you're looking for.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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