FTP automation script

Hi,
I have got a requirement like this.

a parameterized function custFtp which will take 5 i/ps and will do the following tasks.

p1) server name
p2) username
p3) password
p4) path name of the server where the file resides
p5) file name pattern

the function will work like this.
custFtp <servername> <username> <password> <pathname> <filename>

The basic flow is given like this.
(custFtp)
|
| login
|---------|
success | | fail
| |
(checkfile) (sendmailtousers)
|
|
|
|-------------|
| |
file exist | |No files
| (sendmailtousers)
|
(checkfilesize)
|----------------|
| |
match | |does not match
next process (checkfile)

Can anyone please help me out in this regard.I have goen through the existing posts.But none of them has this kind of compact scripting.

Please refer to the attached figure to get the process.

Please can anyone help me out in this regard.
Thanks.
Anirban Datta

hey have built up the script myself..............
parameterized......
well help taken from Advanced Bash-Scripting Guide

the script i am pasting below.....

-----------------------------------------------------------------------
#!/bin/sh
#######################################################################
# Script to perform batch ftp. Essentially converts a list of
# of command line arguments into input to ftp.
#
# -h specifies the remote host (default prep.ai.mit.edu)
# -d specifies the remote directory to cd to - you can provide a sequence
# of -d options - they will be cd'ed to in turn. If the paths are relative,
# make sure you get the sequence right. Be careful with relative paths -
# there are far too many symlinks nowadays.
# (default is the ftp login directory)
# -v turns on the verbose option of ftp, and shows all responses from the
# ftp server.
# -f remotefile[:localfile] gets the remote file into localfile
# -m pattern does an mget with the specified pattern. Remember to quote
# shell characters.
# -c does a local cd to the specified directory
# -u specifies the user
# -p specifies the password
# For example,
# ftpget -h expo.lcs.mit.edu -d contrib -u iuser -p ipassword -f xplaces.shar:xplaces.sh \
# -d ../pub/R3/fixes -c ~/fixes -m 'fix*'
# will get xplaces.shar from ~ftp/contrib on expo.lcs.mit.edu, and put it
# in xplaces.sh in the current working directory, and get all fixes from
# ~ftp/pub/R3/fixes and put them in the ~/fixes directory.
# Obviously, the sequence of the options is important, since the equivalent
# commands are executed by ftp in corresponding order
#
###########################################################################
#

E_BADARGS=65
TMPFILE=/tmp/ftp.`date "+%Y%m%d%H%M%S"`
LOGFILE=ftp.`date "+%Y%m%d%H%M%S"`
# ==> Creates temp file, using process id of script ($$)
# ==> to construct filename.
SITE=$2
# ==> May rewrite this to parameterize this for general use.
usage="Usage: $0 [-h remotehost] [-d remotedirectory]... \
[-f remfile:localfile]... [-c localdirectory] [-m filepattern] [-v]"
echo "user ${USER-gnu} loging into site ${SITE} > ${TMPFILE}"
echo "user ${USER-gnu} loging into site ${SITE} > ${LOGFILE}"
ftpflags="-i -n"
verbflag=
set -f # So we can use globbing in -m
set x `getopt vh:u:p:d:c:m:f: $`
if [ $? != 0 ]; then
echo $usage
exit $E_BADARGS
fi
shift
trap 'rm -f ${TMPFILE} ; exit' 0 1 2 3 15
# ==> Signals: HUP INT (Ctl-C) QUIT TERM
# ==> Delete tempfile in case of abnormal exit from script.
for i in $
# ==> Parse command line args.
do
case $i in
-v) verbflag=-v; shift;;
-h) echo open $2 >> ${TMPFILE}; shift 2;;
-u) remuser=$2; shift 2;;
-p) echo user ${remuser} $2 >> ${TMPFILE}; echo binary >> ${TMPFILE}; shift 2;;
-d) echo cd $2 >> ${TMPFILE};
if [ x${verbflag} != x ]; then
echo pwd >> ${TMPFILE};
fi;
echo "ls -l /tmp/filesize.log" >> ${TMPFILE}
shift 2;;
-c) echo lcd $2 >> ${TMPFILE}; shift 2;;
-m) echo mget "$2" >> ${TMPFILE}; shift 2;;
-f) f1=`expr "$2" : "\([^:]*\)."`; f2=`expr "$2" : "[^:]*:\(.\)"`;
echo get ${f1} ${f2} >> ${TMPFILE}; shift 2;;
--) shift; break;;
esac
# ==> 'lcd' and 'mget' are ftp commands. See "man ftp" . . .
done
if [ $# -ne 0 ]; then
echo $usage
exit $E_BADARGS
# ==> Changed from "exit 2" to conform with style standard.
fi
if [ x${verbflag} != x ]; then
ftpflags="${ftpflags} -v"
fi
if [ x${remhost} = x ]; then
remhost=10.244.187.29
# ==> Change to match appropriate ftp site.
fi
echo quit >> ${TMPFILE}
# ==> All commands saved in tempfile.
ftp ${ftpflags} < ${TMPFILE} >> ${LOGFILE}
# ==> Now, tempfile batch processed by ftp.
# Now checking the ftp status
if [ $? -ne 0 ];then
echo "Error in the FTP file moving. on `date` " >> ${LOGFILE}

cnt=`grep -c "Transfer complete" ${LOGFILE}`

if [ $cnt -eq 0 ];then
cnt1=`grep -c "logged in" ${LOGFILE}`

if [ $cnt1 -eq 0 ];then
echo "Invalid username or password" >> ${LOGFILE}
else
echo "FTP failed" >> ${LOGFILE}
fi
fi

exit 0
else
echo "The FTP file is moved successfully.." >> ${LOGFILE}
fi

rm -f ${TMPFILE}
# ==> Finally, tempfile deleted (you may wish to copy it to a logfile).
-----------------------------------------------------
usage:
sh ftpget1.ksh -h <server ip> -u <username> -p <password> -c <local directory> -d <remote dir> -f <remote file>:<loacl file> -v

--------------------------------------------------------

hopefully u can get help from here...