#!/bin/ksh Email1="myname@compname.com" #Path of Log file logdir="/log/ftp" # Path of ftp executable ftp="/usr/bin/ftp" # Give port or mention server name IP="111.111.111.111" #User ID to login into remote server user="ftp" #Password to login in remote server pass="ftp" #Mention the path where the file to FTP is lying in the current server ifile="/mainfold/level2fold/filetoftp" #Mention the path where the FILE need to FTPied in the remote server ofile="xyz/filename" #Mention type of data transfer "asc" or "bin" type="asc" # this will take the name of your file myname=`basename $0` #selects the mode verbose="verbose" #date of FTP - Current date dd=`date +%d` # Creating a log file with datestamp log="$logdir/$myname.$dd.log" host=`hostname` rc=0 boj=`date` #ftp block starting - all will be written to log file exec 1>$log 2>&1 echo "---------------------------------------------------" echo " Begin FTP Parameters " echo "---------------------------------------------------" echo "Email Sent To $Email1 " echo "Destination Machine: $IP" echo "User ID: $user" echo "Password: ##############" echo "Destination File: $ofile" echo "---------------------------------------------------" echo " End FTP Parameters " echo "---------------------------------------------------" echo " Begin FTP Session " echo "---------------------------------------------------" echo "open $IP quote USER $user quote PASS $pass $verbose $type put $ifile $ofile close quit" |$ftp -n echo "---------------------------------------------------" echo " End FTP Session " echo "---------------------------------------------------" # FTP block ends #Check the log file for FTP status foo=`grep -i "cannot" $log` if [ "$?" -eq "0" ] ; then rc=1 status="Destination file does not exist\n" fi foo=`grep -i "does not" $log` if [ "$?" -eq "0" ] ; then rc=1 status="${status}Source file does not exist\n" fi foo=`grep -i "killed" $log` if [ "$?" -eq "0" ] ; then rc=1 status="${status}File transfer process has abended\n" fi foo=`grep -i "space" $log` if [ "$?" -eq "0" ] ; then rc=1 status="${status}Ran out of disk space before completion of copy\n" fi if [ "$rc" -eq "0" ] ; then status="Successful" fi # find out the time to ftp. eoj=`date` echo "\nJob start time: $boj" echo "Job end time: $eoj" echo "\nResult code: $rc ($status)" #Mail the status to the email address specified. mailx -s "FTP results from $myname" $Email1 <$log exit 0