#!/bin/sh
#
# Given an arglist of ftp URLs, fetch them to the current directory
#
# Anticipated usage: get-patches [-p] `new-patches`
#
# Corey Satten, corey @ cac.washington.edu, 9/01/02, release 1.1

FTP=pftp			# first try passive mode via pftp
$FTP </dev/null 2>&- || FTP=ftp	# if pftp doesn't exist, use ftp

for i in $*; do
    case "$i" in
	-h) HASH='hash';;
	-p) PASV='passive';;
	ftp://*)
	    HST=`echo "$i" | sed "s,^ftp://,,; s,/.*,,"`
	    DIR=`echo "$i" | sed "s,^ftp://$HST/,,; s,/[^/]*$,,"`
	    FIL=`echo "$i" | sed "s,^ftp://$HST/$DIR/,,"`
	    echo -n $FIL...
	    ( echo user ftp $USER@
	      echo cd $DIR
	      echo $HASH
	      echo $PASV
	      echo bin
	      echo get $FIL
	      ) | $FTP -n $HST
	    echo done
	    ;;
	http://*)
	    wget "$i";;
    esac
    sleep 1	# allow this script to be interruptable
done
