cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: shell scripts using curl?

From: Daniel Stenberg <daniel-curl_at_haxx.se>
Date: Wed, 12 Jan 2005 23:00:05 +0100 (CET)

On Wed, 12 Jan 2005, Bill Mercer wrote:

> Among other things, I'm trying to set up a sort of custom mirroring script
> that will retrieve a directory listing, parse the results, compare them to a
> couple of local directories, and then retrieve files that don't exist
> locally. It's not a straightforward mirror, because the files may get
> renamed and moved around a bit on the local machine, which is why I can't
> use wget.

I once made something like that in a perl script, but a quick and rough
version of what you describe can be written similar to this (feel free to
extend and make usable):

#!/bin/sh

root="ftp://ftp.sunet.se/pub/gnu/autoconf/"
files=`curl -s -l $root`

f=`echo $files| tr -d '\015'`

for each in $f; do

  echo "check $each"

  if [ -r $each ]; then
    echo "$each is already present"
  else
    echo "getting $root$each"
    curl -s -o "$each" "$root$each"
  fi

done

-- 
      Daniel Stenberg -- http://curl.haxx.se -- http://daniel.haxx.se
       Dedicated custom curl help for hire: http://haxx.se/curl.html
Received on 2005-01-12