Automatic FTP script

We are using SCO OS 5.05 server and we are doing a manual ftp to another SCO OS 5.05 server to backup our database.
We are using the Bourne shell.
We would like to automate the ftp backup of our database instead of doing it manually.
It would be nice to run a script.
Also would there be anyway to hide the ftp password?
Any tips or help would be appreciated.
Please advise and thanks.

Here is a simple simple ftp script you can follow: Not much luck on encrypting the password so you can not read it though.

 
#! /usr/bin/ksh

HOST=remote.host.name
USER=whoever
PASSWD=whatever

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
print -p cd directory
print -p binary
print -p put tar.gz
print -p bye

wait
exit 0

That isn't working at all.
Please advise.
Thanks

You could store the password in a file encrypted by crypt(1) get your script to decrypt it as it uses it, not very secure but it would hide the password from the casual observer.

I've used ftp with an input file to give the commands before, e.g.:

$ cat cmdfile.template
open _FTPSERVER_
user _USER_ _PASSWORD_
cd directory
binary
put tar.gz
bye
$

And then a script like this:

HOST=remote.host.name
USER=whoever
PASSWD=whatever

sed -e 's/_FTPSERVER_/'${HOST}'/' -e 's/_USER_/'${USER}'/' -e 's/_PASSWORD_/'${PASSWD}'/' cmdfile.template > cmdfile
ftp < cmdfile

If you wanted to hide the password then encrypt it into a file using crypt, e.g.:

$ echo passwdofchoice > clear
$ echo keyofchoice > key.file
$ crypt `cat key.file` < clear > password.crypt
$ rm clear

Changing key to be the decryption key and password to ones of your choice.

The in the above script "PASSWD=whatever" would change to:

KEY=`cat key.file`
PASSWD=`crypt ${KEY} < password.crypt`

The filenames could be made more obscure and as I said the whole thing is not secure but it would hide things a bit...

Using scp to transfer files via SSH with passwordless SSH would be preferable and more secure if your ftp server is also running sshd.

For FTP passwords, try a .netrc file in $HOME for the FTP user with permissions 600 owned by root.

man .netrc