here i am sharing my script
#script name: mfileftp.sh
#purpose: Script File for Multiple Files FTP Program which support and ? metachars
#Details: This script generates one log file which contains server output and custom output as names of files ftp to server
# and contain warning message which says which files could not transferred
# log file will be created in the source directory with name ftp_log_ddmmyyhhmn.log
#USAGE: sh mfileftp.sh ftpserver username pwwd d/sourcedirectory d/destinationdir file1...file2...file
# use d as command line parameter for default otherwise put directory
#prerequisite: user must have write permission in the source directory
#Author:
#version: 1.6
v_source_ip=$1
v_user_id=$2
v_pwd=$3
v_source_dir=/usr/sdir #put some directory for default usage
v_dest_dir=/usr/ddir #put some directory for default usage
#this temp file will remain in existance to run commands on ftp prompt, will be deleted at the end of script.
temp=$v_source_dir/temp_ftp.tmp
underscore_char=_
TIMESTAMP=`date +%d%m%y%H%M`
log=$v_source_dir/ftp_log$underscore_char$TIMESTAMP.log
if [ $# -lt 6 ]
then
echo "Improper Usage:$0"
exit
fi
if [ $# -eq 5 ]
then
echo "improper usage:File name missing"
fi
#Remove temp file if exist
if [ -f $temp ]
then
rm $temp
fi
#Remove log file if exist
if [-f $log ]
then
rm -f $log
fi
#Check if file name is given and validate source and destination directory
if [ $# -gt 5 ]
then
if [ $4 = "d" ]
then
echo " Default Source Dir Used : $v_source_dir"
elif [ -d $4 ]
then
v_source_dir=$4
else
echo "Invalid Source directory or Improper Usage"
exit
fi
# check for destination dir
if [ $5 = "d" ]
then
echo " Default Destination Dir Used : $v_source_dir"
else
v_dest_dir=$5
fi
#Creation of temp file from where all the commands will be executed
#changing mode of file so no one else can see it
touch $temp
chmod 700 $temp
#c=`ls -l $temp`
#echo "$c"
echo "user $v_user_id $v_pwd" > $temp
echo "cd $v_dest_dir" >> $temp
echo "lcd $v_source_dir" >> $temp
echo "binary" >> $temp
#echo "hash" >>$temp
#shift first 5 parameters to get files passed in command line
#in loop we check if file exist then we put in command file else we put in error file change ver 1.6
shift 5
while [ $# -gt 0 ];
do
if [ -f $1 ]
then
echo "mput $1" >> $temp
else
echo "file::\" $1 \" do not exist" >>$v_source_dir/ftp_error.err #this file will not be created if all files passed are valid
fi
shift 1
done
echo "bye" >> $temp
#the following command will open ftp session and and run commands from $temp file
#each command will put its message to the $log file as we have redirected output to the file in place of terminal
ftp -nvi $v_source_ip < $temp >$log
#Now we will append our custom message to the log file which will show the names of files transferred during the run
#with grep command we will take those lines contains filenames and put in temp_fill file
#As filenames are second field in the temp_fill file we cut those fields and append it to $log file
echo "\n\n"
echo "Files Transfered in this run...." >>$log
grep "local:" $log>$v_source_dir/temp_fill
cut -f 2 -d" " $v_source_dir/temp_fill>>$log
if [ -f $v_source_dir/ftp_error.err ] #check if err file contains some info then append it to log file ver 1.6
then
echo "\nWarning:\n">>$log #change ver 1.6
cat $v_source_dir/ftp_error.err>>$log #append error message to log file(change ver 1.6)
fi
#following command will display contents of temp file, name of files FTPed to remote machine(change ver 1.6)
echo "files transfered in this run"
cat $v_source_dir/temp_fill
echo "\n"
if [ -f $v_source_dir/ftp_error.err ]
then
echo "\nWarning:\n"
cat $v_source_dir/ftp_error.err #change ver 1.6
fi
fi #end of outer if which checks for no of parameters are greater than five
#remove temp_fill and temp file for security
rm -f $v_source_dir/ftp_error.err #change ver 1.6
rm -f $v_source_dir/temp_fill
rm -f $temp
echo "For more detailed log information please see log file::$log" #change ver 1.6
echo "Automated FTP script completed..."