toucheatout 2006-10-02 10:19 Linux
Even if it's not considered wise to let clear-form passwords in a file, sometimes there is no possibility of authenticating via public keys and therefore backups are only feasible this non-optimum way...
This script would be suitable for off-site backups. Yet, if you have the possibility, i would advise you to use public-key cryptography (with something like ssh, using rsync for instance) to ensure the proper authentication and secrecy of your data.
There is room for improvement though, like using the date to identify the file and maintain a trail of backups. Just replace the server & login information within the script so that they match your configuration. Alternatively, you could use a .netrc file (its usage isn't recommended either).
#!/bin/bash
SCRIPT=`basename $0`
if [ -z "$1" ] ; then
echo "$SCRIPT: Usage: `basename $0` File-one File-two File-three"
exit 1
fi
USER="MyUSER"
SERVER="MySERVER.TLD"
DIRECTORY="/backups"
PASSWORD="aDifficultPAssword"
echo -e "\nStarting to try transmitting to $SERVER...\n"
while [ -n "$1" ] ; do
FILENAME=$1
cat << EOF > /tmp/ftpput_script.$$
user ${USER} ${PASSWORD}
binary
cd $DIRECTORY
put "$FILENAME"
bye
EOF
cat /tmp/ftpput_script.$$ | ftp -n ${SERVER}
echo -e "Processed: $FILENAME";
shift
done
rm -f /tmp/ftpput_script.$$
echo -e "\nDone with all files..."
exit 0