SCP + Find And Search Files Remotely And Copy Locally

This script looks for files in a remote server and then copy them to your local machine.

 

#!/bin/bash

#########################################
## Bash Script to find files on remote ##
## server and copy them to your local  ##
## machine, using find and scp         ##
## Licenced under the GNU GPLv3 licence##
## Author: Guillermo Garron            ##
## Date: 2009-04-10                    ##
#########################################

usage()
{
echo "usage copy-remote.sh [user@server] [path/to/look/in] ['file-pattern-to-look-for']"
echo "Remeber to use the ('') in the pattern"
}

if [ $# != 3 ] 
then
    usage
    exit 1
fi
ssh $1 "find $2 -name '$3'" > /tmp/file-list.txt
while read filename; do
        scp $1:$filename /tmp/;
done < /tmp/file-list.txt