Skip to content

Instantly share code, notes, and snippets.

@cinco
Created August 24, 2021 22:27
Show Gist options
  • Save cinco/fcde0c84a4d3563675420ad106bdab4b to your computer and use it in GitHub Desktop.
Save cinco/fcde0c84a4d3563675420ad106bdab4b to your computer and use it in GitHub Desktop.
Sync between two FTPs
#!/bin/bash
DEST_DIR=$(mktemp -d /tmp/ftp-sync-XXXX)
FTP_ORIGIN_HOST=
FTP_ORIGIN_USER=
FTP_ORIGIN_PASS=
FTP_DESTINATION_HOST=
FTP_DESTINATION_USER=
FTP_DESTINATION_PASS=
REJECTED_FILES=
echo "-- Starting FTP Synchro between ${FTP_ORIGIN_USER}@${FTP_ORIGIN_HOST} & \
${FTP_DESTINATION_USER}@${FTP_DESTINATION_HOST} --"
cd $DEST_DIR
echo "\n-- Temporary putting FTP files in $DEST_DIR --"
wget -m --reject ${REJECTED_FILES} ftp://${FTP_ORIGIN_USER}:${FTP_ORIGIN_PASS}@${FTP_ORIGIN_HOST}/
if [ "$?" -ne 0 ]; then
echo 'Error while downloading. Aborting!'
exit
fi
echo '\n-- Uploading files on new FTP --'
cd ${FTP_ORIGIN_HOST}
find . -type f -exec curl -T {} ftp://${FTP_DESTINATION_HOST}/\{\} --user ${FTP_DESTINATION_USER}:${FTP_DESTINATION_PASS} --ftp-create-dirs \;
if [ "$?" -ne 0 ]; then
echo 'Error while uploading. Aborting!'
exit
fi
echo '\n-- Cleaning up --'
rm -rf ${DEST_DIR}
echo '\nJob done!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment