Shell Script for FTP transfers

A part of one of my latest projects was to backup a part of a server and FTP transfer those backups from one server to an other.

IMG_0882

FTP Transfer – 1 file

Here is a bit of code that transfers the backup from one server to an other server that works as remote storage.

!/bin/sh

# Login details for the remote storage. If you want to use the script you need to enter your details here.
USERNAME=”myUsername”
PASSWORD=”myPassword”
SERVER=”myServer ”

# Filename of backup file to be transfered
FILE=”/home/Prayance/myBackups/*.tar.gz”

# Remote server location with the new file name
REMOTE=”location1/location2/myBackups/PrayanceBackup_$(date +%d-%m-%Y).tar.gz”

# login to ftp server and transfer file
ftp -inv $SERVER  <<-EOF
user $USERNAME $PASSWORD
binary
put $FILE $REMOTE
quit
EOF

 

FTP Transfer multiple files

#!/bin/sh
# This script tranfers the SQL backups to remote storage

# Login details for the remote storage (NAS)
USERNAME=”myUsername”
PASSWORD=”myPassword”
SERVER=”myServer ”

# Filename of backup file to be transfered
FILE=”/home/Prayance/backups/backup1.sql”
FILEJ=”/home/Prayance/backups/backup2.sql”

# Remote server location with the new file name
REMOTE=”location1/location2/mySQLBackups/Prayance1Backup_$(date +%d-%m-%Y).sql”
REMOTEJ=”location1/location2/mySQLBackups/Prayance2Backup_$(date +%d-%m-%Y).sql”

# login to ftp server and transfer file
ftp -inv $SERVER <<-EOF
user $USERNAME $PASSWORD
binary
put $FILE $REMOTE
quit
EOF

ftp -inv $SERVER <<-EOF
user $USERNAME $PASSWORD
binary
put $FILEJ $REMOTEJ
quit
EOF

# End of script

s1
FTP – transfer single file
s2
FTP – transfer multiple files

 

Leave a Reply

Your email address will not be published. Required fields are marked *