cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: wildcards for uploads

From: Brian Dessent <brian_at_dessent.net>
Date: Thu, 11 Oct 2007 13:26:28 -0700

Seb wrote:

> WD=~/local/dir
> # We upload files to this URL
> URL=ftp://remote/dir//absolute/path
> # These are the paths that will be fed to curl to upload to the URL above.
> UPLOADFILES=$(find -L ${WD} -name 'source' -prune -o ! -name '*~' \
> -type f -print)
>
> cd ${WD}
> for i in ${UPLOADFILES}; do
> fn="${i#${WD}/}" # strip the working directory part off path
> echo "${fn}"
> curl -v --disable-epsv --ftp-create-dirs -u user:passwd \
> -T ${fn} ${URL}
> done

You can avoid that ${i#${WD}/} ugliness by using -printf '%P\n' instead
of -print in the find command. Or just cd to $WD first and then run
"find .".

Also, it seems quite inefficient to have to invoke curl once for each
file, how about simply:

cd ~/local/dir
FILES=$(find -L . -name 'source' -prune -o ! -name '*~' \
        -type f -printf '%P,' | sed -e 's/,$//')
curl -v --disable-epsv --ftp-create-dirs -u user:passwd \
     -T "{$FILES}" ftp://remote/dir//absolute/path

Brian
Received on 2007-10-11