• Home
  • About Me
  • Contact Me
837 3750 ADS aix backup catalyst cisco cisco ios ftp hmc ibm ios juniper LDAP linux nas network nfs p-series password prestashop radius router sfu ssh steel belted tftp unix vpn windows
more tags
Home

A Basic Shell Script for FTP

Submitted by guvnor on Mon, 01/18/2010 - 18:19
  • ftp
  • linux
  • script
  • Shell
  • unix

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

  • Add new comment
Tiaras Dog Harnesses