Please help with Webdav transfer script

I need help on a script that syncs a directory with a webdav directory.
For example I have the folders:
./upload/
./upload/client
./upload/client/department
./upload/client2
./upload/client2/department

each of these folders contain docs that need to goto the webdav.
also the client names change frequently so I realy would not want to hard code them in.

Here is my non working script w/ the fat cutout.

**********************************************************************************************
# I create a full listing of file names
cd /tmp/upload/
find "`pwd`" -name "*.*" > /tmp/Full_listing.txt;

#I cut down the file names and turn the spaces into %20 for the webdav
cat /tmp/Full_listing.txt | sed -e 's|/tmp/upload/|/|' -e 's| |%20|'> /tmp/Short_listing.txt;

# here is where I tranfer the files
cat /tmp/Short_listing.txt |while read line; do cadaver -t \""http://10.1.1.142:80/ktwebdav/ktwebdav.php""${line}"\" -U "username" -P "password" -S \"/tmp/upload"${line}"\";done

#here is where I delete the temp files
cat /tmp/Full_listing.txt |while read line; do rm \""${line}"\";done

**********************************************************************************************

the problem is cadaver is exec like this:
cadaver -t "http://10.1.1.142:80/ktwebdav/ktwebdav.php/client/department/doc.txt" -U "username" -P "password" -S "/tmp/upload/client/department/doc.txt"

When it should be this:
cadaver -t "http://10.1.1.142:80/ktwebdav/ktwebdav.php/client/department/" -U "username" -P "password" -S "/tmp/upload/client/department/doc.txt"

How do I cutout the documents name?
I have been working on this for a few days and have been unable to find a solution.

Thanks for reading my way to long post.

Here is what I ended up with if this helps anybody. I modified cadaver to do what I needed. Source is available if requested. This is my .bash_login for cygwin.

#########################################################
#!/bin/sh
#list directories and divide into names and paths
cd /tmp/upload
DIR="."

function list_files()
{
if !(test -d "$1")
then echo $1; return;
fi

cd "$1"

for i in *
do
if test -d "$i" #if dictionary
then
list_files "$i" #recursively list files
cd ..
else
echo "$i"| 'pwd' >> /tmp/dir
echo "/""$i""\"" >> /tmp/files
fi

done
}

if [ $# -eq 0 ]
then list_files .
fi

for i in $*
do
DIR="$1"
list_files "$DIR"
shift 1 #To read next directory/file name
done

# Format the file names and paths for the webdav
cat /tmp/dir | sed -e 's|/tmp/upload/|/|' -e 's| |%20|'> /tmp/Short_listing;
paste -d '' /tmp/dir /tmp/files > /tmp/full_files;
cat /tmp/full_files | sed -e 's| |\\\\ |g' -e 's|/tmp/upload/|/tmp/Upload/|'> /tmp/full_files_spaced;
cat /tmp/files | sed -e 's| |\\\\ |g' -e 's|/||' > /tmp/short_files_spaced;
#start building the cadaver command
cat /tmp/Short_listing |while read line; do echo cadaver -t \""http://10.1.1.142:80/ktwebdav/ktwebdav.php""${line}"\" -U "uname" -P "pass" -D \";done > /tmp/d_commands1
cat /tmp/Short_listing |while read line; do echo cadaver -t \""http://10.1.1.142:80/ktwebdav/ktwebdav.php""${line}"\" -U "uname" -P "pass" -A \";done > /tmp/a_commands1
#delete commands
paste -d '' /tmp/d_commands1 /tmp/short_files_spaced > /tmp/d_commands2
sed '/\\"/d' /tmp/d_commands2 > /tmp/d_commands3.sh
chmod 775 /tmp/d_commands3.sh
/tmp/d_commands3.sh > /tmp/log/hist.txt
#add commands
paste -d '' /tmp/a_commands1 /tmp/full_files_spaced > /tmp/a_commands2
sed '/\
\"/d' /tmp/a_commands2 > /tmp/a_commands3.sh
chmod 775 /tmp/a_commands3.sh
/tmp/a_commands3.sh >> /tmp/log/hist.txt
# time to clean up
rm /tmp/*
rm /tmp/upload/*
rm /tmp/upload/*/*
rm /tmp/upload/*/*/*
rm /tmp/upload/*/*/*/*
# log what was done
date >> /tmp/log/failed.log
date >> /tmp/log/Conflict.log
date >> /tmp/log/succeeded.log
cat /tmp/log/hist.txt | grep failed >> /tmp/log/failed.log
cat /tmp/log/hist.txt | grep Conflict >> /tmp/log/Conflict.log
cat /tmp/log/hist.txt | grep succeeded >> /tmp/log/succeeded.log
exit