This script shows you how to automate FTPing to remote server.
First of all create a text file, lets name it as automate.ftp
put the following commands into it.
#############################################
open hostname
user username password
cd desireddirectory
lcd localdirectory
bin
put sourcefile destinationfile
quit
#############################################
Text in bold are variables (It can be changed according your requirements)
use the command below to automatically send the files you put in the above automate.ftp
ftp -i -n < /automate.ftp
You can schedule this in cron if you need it regularly. You can also write a script to generate the above file if your file names changes. A typical expample is below.
Contents of sendftp.ksh which can be scheduled in the cron for executing regularly.
#############################################
DATE=`date +"%Y%m%d.%H%M%S"`
echo "open hostname" > /automate.ftp
echo "user username password" >> /automate.ftp
echo "cd destinationdirectory" >> /automate.ftp
echo "lcd localdirectory" >> /automate.ftp
echo "bin" >> /automate.ftp
echo "put "report.txt `hostname`.$DATE.report.txt >> /automate.ftp
echo "quit" >> /automate.ftp
ftp -i -n < /automate.ftp ############################################# Note: Here report.txt is the source file and destination file would be named as hostname with current date prefixed with report.txt
No comments:
Post a Comment