#!/bin/bash set -e # Exit if error # This script synchronizes data from FTP into local folder: # - remove file that do not exist anymore in the FTP (mirror -e) # # No modification will be done in the FTP. # # Configuration is gathered at the beginning of the script. # ============================================================================= # Configuration # ============================================================================= FTP_USER=ftp FTP_PASS=ftp FTP_IP=192.168.1.30 FTP_PORT=2121 DESTINATION=Phone/ # Local folder where to save files # List of folders to save # example: LINK+=("/distant/dir" "dir2") # will saved FTP folder "/distant/dir" in local folder "$DESTINATION/dir2" LINK=() LINK+=("/DCIM" "DCIM") LINK+=("/Pictures" "Pictures") LINK+=("/Download" "Download") LINK+=("/WhatsApp/Media/WhatsApp Video" "WhatsApp_Video") LINK+=("/WhatsApp/Media/WhatsApp Images" "WhatsApp_Images") LINK+=("/Documents" "Documents") # ============================================================================= echo "=========================================================" echo "Start synchronisation to ${DESTINATION}" echo "=========================================================" find ${DESTINATION} -type f -exec chmod 644 {} \; find ${DESTINATION} -type d -exec chmod 755 {} \; for ((i=0; i<${#LINK[@]}; i+=2)); do DISTANT_DIR=${LINK[i]} LOCAL_DIR=${LINK[i+1]} echo "############################## ${DISTANT_DIR} > ${LOCAL_DIR}" mkdir -p "${DESTINATION}/${LOCAL_DIR}/" if lftp ftp://${FTP_USER}:${FTP_PASS}@${FTP_IP}:${FTP_PORT} -e "mirror -e -x .thumbnails -x "saved" \"${DISTANT_DIR}\" \"${DESTINATION}/${LOCAL_DIR}\" ; quit" ; then echo "Success :)" else echo 'Failed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' fi done