#!/bin/sh

(
mode=ascii
oldd=""
while read f
do
    d=`dirname $f`
    if [ "$d" = "." ]
    then
	d=""
    fi
    b=`basename $f`
    if [ "$d" != "$oldd" ]
    then
	d1=$oldd
	d2=$d
	while [ "$d1" ]
	do
	    dw1=`expr "$d1" : '\([^/]*\)'`
	    dw2=`expr "$d2" : '\([^/]*\)'`
	    if [ "$dw1" != "$dw2" ]
	    then
		break
	    fi
	    d1=`expr "$d1/" : '[^/]*/*\(.*\)/'`
	    d2=`expr "$d2/" : '[^/]*/*\(.*\)/'`
	done
# this could be optimized, but AT&T's server is lame
	if [ "$d1" != "" ]
	then
	    d1=`echo "$d1" | sed 's/[^/]*/../g'`
	    echo "cd $d1"
	    echo "lcd $d1"
	fi
	if [ "$d2" != "" ]
	then
	    echo "mkdir $d2"
	    echo "cd $d2"
	    echo "lcd $d2"
	fi
	oldd=$d
    fi
    case "$b" in
    *.html|*.aix)
	newmode=ascii
	;;
    *)
	newmode=binary
	;;
    esac
    if [ "$mode" != "$newmode" ]
    then
	echo $newmode
	mode=$newmode
    fi
    if [ "$b" = "mediaone-index.html" ]
    then
	echo "put $b index.html"
    else
	echo "put $b"
    fi
done < upload-list
echo "quit"
) | ftp -v upload.attbi.com
