Path: utzoo!attcan!uunet!lll-winken!lll-tis!mordor!joyce!ames!scubed!sweet
From: sweet@scubed.UUCP (Kevin Sweet)
Newsgroups: comp.windows.x
Subject: Re: ftp'ing from expo
Message-ID: <787@scubed.UUCP>
Date: 3 Jun 88 19:04:52 GMT
References: <5612@venera.isi.edu> <6162@well.UUCP> <8122@lll-winken.llnl.gov>
Reply-To: sweet@scubed.UUCP (Kevin Sweet)
Organization: S-CUBED, San Diego, California
Lines: 175

In article <8122@lll-winken.llnl.gov> brooks@maddog.UUCP (Eugene D. Brooks III) writes:
>In article <6162@well.UUCP> Jef Poskanzer  writes:
>>Hey Paul, perhaps it would be appropriate for you to learn how to ftp
>>from a batch job.
>Please post the directions to do this!  I have been wanting to ftp
>in batch mode for some time and have never figgured it out.

I don't see any smiley's here so (here's something better than a 
moderate flame :-):

I wrote a shell script to automate (anonymous) ftp'ing. I got the 
andrew toolkit this way. (Just nohup the beast.)

#---cut here---cut here---cut here---cut here---cut here---cut here---
#! /bin/sh
# This is a shell archive, meaning:
#     1. Remove everything above the #! /bin/sh line.
#     2. Save the resulting text in a file.
#     3. Execute the file with /bin/sh (not csh) to create:
#        aftp
# This archive created: Fri Jun  3 12:03:48 PDT 1988
#
echo shar: extracting "aftp" '(2851 characters)'
if test -f aftp
then
  echo shar: will not over-write existing file "aftp"
else
sed 's/^XX//' << \SHAR_EOF > aftp
XX#!/bin/sh
XX# usage: aftp [-a|b|t] [-h host] [-d [rdir]] [rdir] rfile [lfile]
XX#
XX# where: [-a|b|t] 	selects (a)scii, (b)inary, or (t)enex transfer
XX#			ascii is the default
XX#        [-h host]	is the host name to ftp from
XX#        [-d [rdir]]	is the remote directory name to get files from
XX#			[rdir] defaults to .
XX#			if you don't select any files, you get a 
XX#			directory listing 
XX#			(e.g., aftp -h expo.lcs.mit.edu -d pub/X.V11R2)
XX#        [rdir]		is the remote directory name to get files from
XX#        rfile		is the remote file to get (or mget)
XX#			(e.g., aftp -t -h expo.lcs.mit.edu 
XX#			            pub/X.V11R2/contrib.hc '*.split.*')
XX#        [lfile]	is the (optional) local filename
XX#			(e.g., aftp -t -h expo.lcs.mit.edu contrib 
XX#			            pbm.tar.Z poskbitmaps.t.Z)
XX#
XX# author: Kevin Sweet [sweet@scubed.arpa]
XX#
XX
XXPATH=/bin:/usr/bin:/usr/ucb
XXProgram=`basename $0`
XXNetrc=${HOME}/.netrc
XXrm -f $Netrc
XX
XXHost=$HOST
XXLogin="anonymous"
XXPassword="guest"
XXTransfer="ascii"
XXDir= Ddir= Local= Remote= 
XXwhile test $# != 0
XXdo	case "$1" in
XX	-l)	case "$2" in
XX		-*|"")	;;
XX		*)	Login="$2" ; shift ;;
XX		esac ;;
XX	-l*)	Login=`expr $1 : '-.\(.*\)'` ;;
XX	-p)	case "$2" in
XX		-*|"")	;;
XX		*)	Password="$2" ; shift ;;
XX		esac ;;
XX	-p*)	Password=`expr $1 : '-.\(.*\)'` ;;
XX	-h)	case "$2" in
XX		-*|"")	;;
XX		*)	Host="$2" ; shift ;;
XX		esac ;;
XX	-h*)	Host=`expr $1 : '-.\(.*\)'` ;;
XX	-d)	case "$2" in
XX		-*|"")	Ddir="." ;;
XX		*)	Ddir="$2" ; shift ;;
XX		esac ;;
XX	-d*)	Ddir=`expr $1 : '-.\(.*\)'` ;;
XX	-a*)	Transfer="ascii" ;;
XX	-b*)	Transfer="binary" ;;
XX	-t*)	Transfer="tenex" ;;
XX	-*)	;;
XX	*)	if test "$Dir" = ""; then
XX			Dir="$1" ; 
XX		elif test "$Remote" = ""; then
XX			Remote="$1" ; 
XX		else
XX			Local="$1" ; 
XX		fi ;; 
XX	esac
XX	shift
XXdone
XXif test "$Ddir" != ""; then
XX	Local="$Remote"
XX	Remote="$Dir"
XX	Dir="$Ddir"
XXfi
XX
XXListing= 
XXif test "$Host" = ""; then
XX	echo -n 'usage: '$Program' [-a|b|t] [-h host] [-d [rdir]] '
XX	echo '[rdir] rfile [lfile]'
XX	exit 0
XXelif test "$Remote" = ""; then
XX	if test "$Ddir" = ""; then
XX		echo -n 'usage: '$Program' [-a|b|t] [-h host] '
XX		echo '[-d [rdir]] [rdir] rfile [lfile]'
XX		exit 0
XX	else
XX		Listing=yes
XX	fi
XXfi
XX
XXif test `echo $Remote | grep -c '*'` -ne 0; then
XX	Get="mget"
XX	Local= 
XXelif test `echo $Remote | grep -c '?'` -ne 0; then
XX	Get="mget"
XX	Local= 
XXelif test `echo $Remote | grep -c '\['` -ne 0; then
XX	Get="mget"
XX	Local= 
XXelse
XX	Get="get"
XX	if test "$Local" = ""; then
XX		Local="$Remote"
XX	fi
XXfi
XX
XXecho "machine $Host, login $Login, password $Password" > $Netrc
XXchmod 600 $Netrc
XX	if test "$Listing" = "yes"; then
XXecho listing of directory $Dir on $Host:
XXftp -v $Host << END_FTP
XXcd $Dir
XXdir
XXbye
XXEND_FTP
XX	else	# listing
XXdate
XXecho -n $Transfer transfer of $Host::$Dir/$Remote
XXif test "$Get" = "get"; then
XX	echo ' to '$Local':'
XXelse
XX	echo :
XXfi
XXftp -v -i $Host << END_FTP
XX$Transfer
XXcd $Dir
XX$Get $Remote $Local
XXbye
XXEND_FTP
XXecho ' '
XX	fi	# listing
XXrm -f $Netrc
XX
XXexit 0
SHAR_EOF
if test 2851 -ne "`wc -c < aftp`"
then
  echo shar: error transmitting "aftp" '(should have been 2851 characters)'
fi
fi # end of overwriting check
#
# End of shell archive
exit 0

-- 
Kevin Sweet ---------------------------------- sweet%kelvin@scubed.arpa
S-CUBED, 3398 Carmel Mountain, San Diego, CA 92121-1095,  (619)587-8499
UUCP:    [harvard,ihnp4!ames,rutgers,ucsd,uunet]scubed!kelvin!sweet
DECNET:  SDSC::"SWEET@S3VAX.SPAN" , 1.312::SWEET