Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automate a FTP connection?? 1

Status
Not open for further replies.

razor192

MIS
May 23, 2002
2
US
I'm looking for a way to automate a FTP connection from SCO to a Windows FTP server.. anyone ever done this?
 
There are many methods of doing this, from using Perl to just using Ncftp. I've only done this with expect scripts.

If you google for 'expect script ftp' you may come across a few more ideas.
 
I prefer one of two methods.

#1. ncftpput (which you can install from the Skunkware distribution).

#2. using standard ftp and a $HOME/.netrc script.

ncftpput is the best, but I've come up against some broken ftpd's that won't allow standard directory listings, which means I had to use standard ftp.

Here's a template ftp script for you for standard ftp...

[tt]
-----------------------------------------------------------
#!/bin/ksh
BASE_DIR=/usr/spool/ftpdistrib
FTPDIR=${BASE_DIR}/ftp
HOME=$FTPDIR
NETRC=${FTPDIR}/.netrc
REMOTEDIR=.

DESTIP=192.168.0.1
USER=ftpuser
PASSWD=ftppass

LOGFILE=${FTPDIR}/ftp.log
GETLOGFILE=${FTPDIR}/ftpgetlog.txt

WARN=myemail@address.com

function init
{
echo "Initializing ftp ls at $(date)" >> $LOGFILE
}

function build_netrc
{

if [ ! -d $HOME ]
then
mkdir $HOME
fi

> $NETRC
chmod 600 $NETRC
echo "machine $DESTIP
login $USER
password $PASSWD
macdef init
binary
prompt
cd $REMOTEDIR
mget *
mdel *
quit



" > $NETRC
}


function do_ftp
{
ping -c 5 $DESTIP > /dev/null
if [ $? -ne 0 ]
then
echo "ERROR: $DESTIP is down transfer aborted" >> $LOGFILE
echo | mail -s "$DESTIP is down" $WARN
sleep 5
exit 1
fi
cd $FTPDIR
echo "Starting ftp at `date`" >> $LOGFILE
ftp -v $DESTIP $PORT > $GETLOGFILE 2>&1
echo "Finished ftp at `date`" >> $LOGFILE
}


function clean_up
{
rm $NETRC
}


init
build_netrc
do_ftp
clean_up
-----------------------------------------------------------
[/tt]

ncftpput/get are fantastic, unlike standard ftp which could
timeout, or otherwise fail, where it may be hard to recover,
ncftpput/get have return codes for almost every contingency,
or you could even use the ncftp spooler to retry upon failures automatically.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top