LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to Shell Script auto ftp connection? (https://www.linuxquestions.org/questions/linux-general-1/how-to-shell-script-auto-ftp-connection-158579/)

mtn356 03-16-2004 03:59 PM

How to Shell Script auto ftp connection?
 
Hi,

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,

Mike.

Tinkster 03-16-2004 04:27 PM

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


Cheers,
Tink

/bin/bash 03-16-2004 05: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 ftp.box2.com 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.

#!/bin/bash
cd /path/to/mysqldumpfile
lftp <<EOF
open ftp.box2.com
cd /path/to/mysqlsavefile
pwd
ls
put mysqldumpfile
bye
EOF

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 07:59 AM

worked great.


Thank you.

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

You're welcome.


All times are GMT -5. The time now is 04:06 AM.