A Basic Shell Script for FTP
Basic FTP Shell Script for uploading files
Introduction
There are occasions where you might want to FTP data off site from a server or other host onto an FTP server
NOTE! Think a little before using FTP. It doesn't send login credentials (username / password) it an encrypted form and the data it transfers is not encrypted either. There are some security implications to using FTP as transfer protocol over public links.
#!/bin/bash
# Please change the following variables to suit your hosts environment.
#Set the directory path where you want your backups stored assign it to the variable BACKUPDIR
BACKUPDIR=/home/myuser/backups
#Since we are "zipping" our backup into one file set that tar file name and assign it to the variable ZIPARCHIVE. If you prefer to use tar that works as well.
ZIPARCHIVE=myarchivename
#Set the path of the directory you want backed up. In this case it the path of a website
DATA=/apache/htdocs/mywebsite/
#Set the FTP host / User and password
FTPHOST=ftp.myserver.com
FTPUSER=myftpuser
FTPPASSWORD=mypassw0rd
#get the system date and assign it to the variable BACKUPDATE
BACKUPDATE=`date +%Y-%m-%d`
### No need to Modify script after this line ###############################
zip -q -r -9 $BACKUPDIR/$BACKUPDATE.$ZIPARCHIVE.zip $DATA
cd $BACKUPDIR
/usr/bin/ftp -in <<EOF
open $FTPHOST
user $FTPUSER $FTPPASSWORD
bin
verbose
put $BACKUPDATE.$ZIPARCHIVE.zip
stat
bye
#Now we have FTPed the file you can delete the zip file. Hash # this one out if you don't want to delete the zip after the transfer is complete.
rm -f $BACKUPDIR/$BACKUPDATE.$ZIPARCHIVE.zip
