#!/bin/bash

. ./param_bash.ini

FTP_TEMPL=$1
IKIT_FTP_DIR=$3
MAIL=$4
if [ "$2" = "ver" ] ; then
	USER=$FTP_USER
	PASSWD=$FTP_PASSWD
        stat_file=ROSETTA_SOFT_FTP_COMPLETED
elif [ "$2" = "prd" ] ; then
	USER=$PRD_FTP_USER
	PASSWD=$PRD_FTP_PASSWD
        stat_file=ORA_SOFT_FTP_COMPLETED
else
	USER=$FTP_USER
	PASSWD=$FTP_PASSWD
        stat_file=ROSETTA_DB_FTP_COMPLETED
fi


rm -f $IKIT_DIR/*FTP_COMPLETED >& /dev/null
rm -f $IKIT_DIR/*FTP_FAILED >& /dev/null

################################################################################

count=1
for i in `cat $FTP_TEMPL`
do
        $PS | grep ftp_listener_${2} | grep -v grep >& /dev/null 
        if [ "$status" != 0 ] ; then
            cd ${IKIT_FTP_DIR}
            $WGET -o $IKIT_DIR/log/ftp_${2}_${count}.log ${WGET_OPTS} "ftp://${USER}:${PASSWD}@${FTP_SERVER}${i}/*"
            cd ${IKIT_DIR}
            let count=count+1
            sleep 3
        fi
done
$PS | grep ftp_listener_$2 | grep -v grep >& /dev/null
if [ "$?" != "0" ] ; then        
        bash -f ftp_listener_${2} "$FTP_TEMPL" "$IKIT_FTP_DIR" "$MAIL" &
fi
