Created
May 12, 2019 17:15
-
-
Save shyamjos/13950863185472c296dd60b46e9e95d0 to your computer and use it in GitHub Desktop.
lftp bulk file upload script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#lftp upload Script shyam jos 2017 | |
# turn off history substitution to allow special chars in password | |
set +H | |
LFTPDUSER="company_user" | |
LFTPDPASSWORD="4Po0ebL!@q5E" | |
#insert date for loging | |
echo -n "$(date) : " >> /var/log/lftp.log | |
#check if ftp password is correct | |
echo "Checking Password..." | |
if [ -f /var/log/lftp.lock ]; then | |
echo " Authentication Failed!! Check password !: Note: A lock file /var/log/lftp.lock is created to prevent script execution !! " >> /var/log/lftp.log 2>&1 | |
echo "Exiting... Lock file found /var/log/lftp.lock - Check Password!!" | |
exit 1 | |
fi | |
lftp -u "$LFTPDUSER,$LFTPDPASSWORD" sftp://10.94.140.105 -e "cd /home/company_user ; bye" >> /var/log/lftp.log 2>&1 || touch /var/log/lftp.lock | |
if [ -f /var/log/lftp.lock ]; then | |
echo "Authentication Failed!! Check password !: Note: A lock file /var/log/lftp.lock is created to prevent script execution !!" >> /var/log/lftp.log 2>&1 | |
echo "Exiting... Lock file found /var/log/lftp.lock - Check Password!!" | |
exit 1 | |
else | |
echo "Password OK!" | |
fi | |
# Check if source dir is empty | |
if [ -n "$(find /home/files-to-upload/ -maxdepth 0 -type d -empty 2>/dev/null)" ]; then | |
echo "Error: No Files to upload" >> /var/log/lftp.log 2>&1 | |
echo "Error: No files found in /home/files-to-upload/" | |
exit 1 | |
fi | |
#copy files to ftp server | |
echo "Uploading..." | |
lftp -u "$LFTPDUSER,$LFTPDPASSWORD" sftp://10.94.140.105 -e "mput -O /home/company_user /home/files-to-upload/* ; bye" >> /var/log/lftp.log 2>&1 && echo "file transfer successful" >> /var/log/lftp.log 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment