I wrote a bash script for uploading backup files from a server to a ftp server. But I always get an error.
Name (myftpserver:root): Permission denied.
Login failed.
Login with USER first.
Please login with USER and PASS.
Local directory now /backup01
Please login with USER and PASS.
Passive mode refused.
That's my script:
#!/bin/bash
DATE=`date +%Y-%m-%d_%H%M`
LOCAL_BACKUP_DIR="/backup01"
DB_NAME="databasename"
DB_USER="root"
FTP_SERVER="randomIP"
FTP_USERNAME="myname"
FTP_PASSWORT="supersecret"
FTP_UPLOAD_DIR="/home/mydirectory/ftp/upload"
LOG_FILE=/backup01/backup-$DATE.log
mysqldump -u $DB_USER $DB_NAME | gzip > $LOCAL_BACKUP_DIR/$DATE-$DB_NAME.sql.gz
ftp $FTP_SERVER << END_FTP
quote USER $FTP_USERNAME
quote PASS $FTP_PASSWORD
cd $FTP_UPLOAD_DIR
lcd $LOCAL_BACKUP_DIR
put "$DATE-$DB_NAME.sql.gz"
bye
END_FTP
if test $? = 0
then
echo "Database successfully uploaded to the FTP Server!"
echo "Database successfully created and uploaded to the FTP Server!" | mail -s "Backup from $DATE" my.email@whereever.com
else
echo "Error in database upload to Ftp Server" > $LOG_FILE
fi
Maybe someone can help me, because I've tried everything I've found on the internet. I've made a .netrc file. I configured the vsftpd.conf, enabled passiv mode, enabled user list and I've made a lot of other stuff... But now I'm having no idea what else I have to do to make this script working the way it should. And I have no idea why it's trying to connect via root...
Maybe there is someone out there who can help. Thanks in advance.