-   Linux - General (
-   -   How to Shell Script auto ftp connection? (

mtn356 03-16-2004 04:59 PM

How to Shell Script auto ftp connection?

Currently I backup our mysql databases from are Red Hat ES 2.1 maintained by a web hosting provider manually. This means I run mysqldump and download the file each day. I would like to shell script the process if possible. I have the mysqldump portion complete now I just need to connect up to our local ftp server and drop the data. I cannot seem to get past the username and password part. Has anybody done anything like this that can help me. Or maybe just a better approach than ftp all together? We have a dedicated soulution so I have full access to the box to run what I need.

Thank You,


Tinkster 03-16-2004 05:27 PM

You may consider setting the machines up
so they allow passwordless ssh connections,
and then just scp stuff back and forth.


/bin/bash 03-16-2004 06:31 PM

Box1 = Backup box with mysql database
Box2 = Remote ftp

On box1 create a .netrc file with entrie like this and save it in your home directory.

machine login yourlogin password yourpassword

NOTE: yourlogin must be a valid login on Box2 and needs write privledges to the save to the directory directory.

Now create a script like this. NOTE you may need to tweek this script a little for your situation.

cd /path/to/mysqldumpfile
lftp <<EOF
cd /path/to/mysqlsavefile
put mysqldumpfile

You can edit crontab and have the script run at a preset time each day.

I don't know what all versions of ftp this will work with but I use similar scripts with lftp and they work.

<edit>CAUTION!!! Make sure .netrc file is chmod 600. Very important for security reasons.

mtn356 03-18-2004 08:59 AM

worked great.

Thank you.

/bin/bash 03-18-2004 08:31 PM

You're welcome.

All times are GMT -5. The time now is 07:26 PM.