Subject: Re: automated FTP sessions

From: Denise Tjong <[email-masked]>
Date: Wed, 27 Mar 1996 08:56:29 -0500

On Thu, 28 Mar 1996, Fundamental wrote:

> does anyone know how i could automate an ftp session?

You could use Expect to automate an ftp session. I've done it and 
the scripts work great.

Denise

---

From: [email-masked] (David Sears)
Date: Wed, 27 Mar 96 10:22:08 MST

>From "Fundamental <[email-masked]>" on Tue Mar 26 23:17:38 1996

> i have a scrip which backs up certain files at certain times (tcsh) it 
> tars them to disk, then i would like it to automagically ftp to another 
> machine on the same network, login and put the files there?
>  
> any ideas how?
>  
> thanx 
 
Here is a script we use.  Works well with anonymous FTP sites, cron and at.
For non-anonymous FTP sites you need to plug in your username and password, a
debatable practice.

In this example, the script is getting the file 

	ftp.microsoft.com:/softlib/mslfiles/pw1118.exe

and storing it in "/tmp" on the local host.  Done via anonymous FTP.  

Hope it is of some use...

David

...BEGIN "getftp.sh" script...
#!/bin/sh
 
#
# getftp.sh - Use anonymous FTP to transfer a file
#
 
MYNAME=`basename $0`		# Name of this script
MAILER=/usr/ucb/Mail		# How do I send e-mail
MAILTO=dmsears			# Send e-mail to
UNAME=anonymous			# FTP username
PASSWORD=[email-masked]	# FTP password
RHOST=ftp.microsoft.com		# set hostname to FTP to
RDIR="softlib/mslfiles"		# set remote directory on FTP site
RFILE=pw1118.exe		# set filename on FTP site to get
LDIR=/tmp			# Local directory
 
cd $LDIR

ftp -nv > ftp.log <<-EOF
        open $RHOST
        user $UNAME $PASSWORD
        cd $RDIR
        bin
        get $RFILE
        quit
EOF
 
STAT=$?
 
$MAILER -s "$MYNAME file=${LDIR}/$RFILE ($STAT)" $MAILTO < /dev/null

exit $STAT
...END "getftp.sh" script...

---

From: [email-masked]
Date: Wed, 27 Mar 1996 18:10:37 +0000

I have done this also as discribed below, look at .netrc 
 ( man netrc ) this will automate the login procedure to
 the HOST you are connecting to. I just did this for a
 client in N.C. so I know it works.
 
> Date:          Wed, 27 Mar 1996 00:35:07 -0600 (CST)
> Reply-to:      [email-masked]
> From:          Andy Ellsworth <[email-masked]>
> To:            [email-masked]
> Subject:       Re: automated FTP sessions

> If you simply make a text file that contains the appropriate commands, 
> pipe it into FTP, and pipe the output to a file (or /dev/null), that 
> should work.  Something like:
> 
>   ftp < foo.txt > ftp-log.txt
> 
> -should- work fine.  (With the emphasis on 'should' -- I've done what you 
> describe before, but it's been a while, and the details are a bit 
> sketchy...but you get the general idea.)
> 
> 
> Andy Ellsworth             | "...The wind was not the beginning.  There are
> [email-masked]         | neither beginnings nor endings to the turning of
> Assistant Admin, wuarchive | the Wheel of Time.  But it was _a_ beginning..."
> http://cec.wustl.edu/~are1 |          --The Wheel of Time saga, Robert Jordan
> 
>