Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sinbadsalmon/40334083af2b753b0beddec6e7730ef5 to your computer and use it in GitHub Desktop.
Save sinbadsalmon/40334083af2b753b0beddec6e7730ef5 to your computer and use it in GitHub Desktop.
Bash script using lftp to mirror local directory to remote directory, thus keeping the remote directory synchronized with the local one. This script uses mirror -R.
#!/bin/sh
# @author: Simon Tipping
# @description: A script to mirror local folder to distant folder using lftp - Based on Alexandre Plennevaux's "MIRROR DISTANT FOLDER TO LOCAL FOLDER VIA FTP" script https://gist.github.com/pixeline/0f9f922cffb5a6bba97a
#
# FTP LOGIN
HOST='sftp://ftp.domain.com'
USER='ftpusername'
PASSWORD='ftppassword'
# DISTANT DIRECTORY
TARGET_DIR='/absolute/path/to/local/directory'
# LOCAL DIRECTORY
SOURCE_DIR='/absolute/path/to/remote/directory'
# RUNTIME!
echo "Starting upload $SOURCE_DIR to $HOST from $TARGET_DIR"
date
lftp -u "$USER","$PASSWORD" $HOST <<EOF
# the next 3 lines put you in ftpes mode. Uncomment if you are having trouble connecting.
# set ftp:ssl-force true
# set ftp:ssl-protect-data true
# set ssl:verify-certificate no
version
# see lftp manual for other options that may be of preference to your circumstances
mirror -R -e --parallel=3 --verbose=1 $SOURCE_DIR $TARGET_DIR;
exit
EOF
echo
echo "Transfer finished"
date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment