|
How To Login Automatically To Ftp
I need to write a shell script, which takes host, user name and password
automatically logs into ftp server.
Solution:
Sample Shell Script on ftp:
#!/bin/ksh
bindir="/home/ftp/bin"
logdir="/home/ftp/log"
ftp="/usr/bin/ftp"
Email="[Some E-mail Address]"
IP="10.124.33.29"
user="[user-id]"
pass="[password]"
ifile="[source file]"
ofile="[destination file]"
type="asc"
myname=`basename $0`
verbose="verbose"
dd=`date +%d`
log="$logdir/$myname.$dd.log"
host=`hostname`
rc=0
boj=`date`
exec 1>$log 2>&1
echo "\n##### Begin FTP Parameters #####\n"
echo "Program Name: $myname"
echo "Process ID:
$$"
echo "Log file name: $log"
echo "Email:
$Email"
echo "Source Machine $host"
echo "Destination Machine: $IP"
echo "User ID:
$user"
echo "Password:
##############"
echo "Source File:
$ifile"
echo "Destination File: $ofile"
echo "\n##### End FTP Parameters #####\n\n"
echo "##### Begin FTP Session #####\n"
echo "open $IP
user $user $pass
$verbose
$type
put $ifile $ofile
close
quit" |$ftp -n
echo "\n##### End FTP Session #####"
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
eoj=`date`
echo "\nJob start time: $boj"
echo "Job end time: $eoj"
echo "\nResult code: $rc ($status)"
mail -s "FTP results from $myname" $Email <$log
Have a Unix Problem
Do you have
a UNIX Question?
Unix Books :-
UNIX
Programming, Certification, System Administration, Performance Tuning Reference
Books
Return to : - Unix
System Administration Hints and Tips
(c) www.gotothings.com All material on this site is
Copyright.
Every effort is made to ensure the content integrity.
Information used on this site is at your own risk.
All product names are trademarks of their respective
companies.
The site www.gotothings.com is in no way affiliated
with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.
|