However while executing the above code , FTIHOST assigns the value UDL_FTIHOST_1 and UDL_FTIHOST_2 not podftiapp02.com and podftiapp01.com
respectively.
Though we would never write script in this manner, the method will only work if you use the Shell eval command to defer processing of the variable until after the value of $i is known. The \$ is important to stop Shell evaluation of the variable name on the first pass.
The eval command has security issues. There is always a better way. In your case a Shell Array might be better but personally I'd have a Shell Function to do the ftp and call it with three parameters.
Ps. The EOF line is missing from the end of the Here Document.
Neither $LOGFILE or $LOG_FILE are set.
Here we go. Totally untested and unwarrented. Rearranged your script to logical order and inserted a function to do the ftp. Removed all lines which become unneeded. Re-ordered your ftp lines because you must log in before issuing commands and also appended a "bye".
LOGFILE=/srv/udl/logs/udl_ftp2fti.log
# Parameters for first transfer
UDL_FTIHOST_1=podftiapp02.com
UDL_FTIUSER_1=dbsunny
UDL_FTIPWD_1=sunny@11
INPUTFILE_1=ADDR3.ALL
target_dir_1=".."
FTP_FILE_1=NVS.DWG.P.GBRSWUDL.ADDR3
# Parameters for second transfer
UDL_FTIHOST_2=podftiapp01.com
UDL_FTIUSER_2=dbamy
UDL_FTIPWD_2=amy@12
INPUTFILE_2="PCPSWAB1.UNDELV.DWNL.TRILL(+1)"
target_dir_2="trillium"
FTP_FILE_2=PCPSWAB1.UNDELV.DWNL.TRILL-900-TEXT.u
transferfile ()
{
echo "Connecting to FTP server to send UDL file...."
ftp -n -v $1 <<EOF >> ${LOGFILE}
user $2 $3
ascii
lcd $4
cd $6
put $5 $7
bye
EOF
}
########################
# Processing starts here
########################
# First transfer
transferfile "${UDL_FTIHOST_1}" "${UDL_FTIUSER_1}" "${UDL_FTIPWD_1}" \
"${UDL_FTIPWD_1}" "${INPUTFILE_1}" \
"${target_dir_1}" "${FTP_FILE_1}"
# Second transfer
transferfile "${UDL_FTIHOST_2}" "${UDL_FTIUSER_2}" "${UDL_FTIPWD_2}" \
"${UDL_FTIPWD_2}" "${INPUTFILE_2}" \
"${target_dir_2}" "${FTP_FILE_2}"
There is still a lot which could go wrong with this script. Most versions of ftp do not like funny filenames or funny characters in passwords.
Good luck.