Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gioxx/8ecebf6036962163c8107f42ba892f36 to your computer and use it in GitHub Desktop.
Save gioxx/8ecebf6036962163c8107f42ba892f36 to your computer and use it in GitHub Desktop.
Bash script using lftp to mirror remote directory to local directory, thus keeping the local directory synchronized with the remote one.
#!/bin/sh
# @author: Alexandre Plennevaux
# @description: MIRROR DISTANT FOLDER TO LOCAL FOLDER VIA FTP
HOST='sftp://ftp.domain.com'
USER='ftpusername'
PASSWORD='ftppassword'
REMOTE_DIR='/absolute/path/to/remote/directory'
LOCAL_DIR='/absolute/path/to/local/directory'
echo
echo "Starting download $REMOTE_DIR from $HOST to $LOCAL_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
set sftp:auto-confirm yes
mirror --delete --only-newer --exclude wp-admin/ --exclude wp-includes/ --use-pget-n=10 $REMOTE_DIR $LOCAL_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