Skip to content

Instantly share code, notes, and snippets.

@jobliz
Last active May 25, 2019 19:02
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 jobliz/e0675b7e422683ea052a3e34794c0145 to your computer and use it in GitHub Desktop.
Save jobliz/e0675b7e422683ea052a3e34794c0145 to your computer and use it in GitHub Desktop.
A script to sync a local directory with a remote directory through FTP.
#!/bin/bash
#
# A script to sync a local directory with a remote directory through FTP. The local directory contents
# will overwrite the remote directory. If a file was deleted locally, it will be deleted remotely.
# Notes:
#
# - It excludes the content of the .git directory.
# - The -P flag is for parallelizing work.
# - 'set ssl:verify-certificate false' might not be necessary. YMMV.
#
# See:
# https://askubuntu.com/questions/758640/how-to-automatically-sync-the-contents-of-a-local-folder-with-the-contents-of-a
# https://serverfault.com/questions/291255/what-is-the-syntax-of-lftps-mirror-x-exclude-option
# https://techoverflow.net/2018/08/07/how-to-disable-ssl-certification-verification-in-lftp/
HOST='example.com'
USER='user@example.com'
PASS='123456'
TARGETFOLDER='/'
SOURCEFOLDER='/home/you/directory'
lftp -f "
set ssl:verify-certificate false
open $HOST
user $USER $PASS
lcd $SOURCEFOLDER
mirror --reverse --only-newer --ignore-time --delete --verbose -P 4 -x ^\.git/$ $SOURCEFOLDER $TARGETFOLDER
bye
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment