From bacchus.pa.dec.com!decwrl!elroy.jpl.nasa.gov!sdd.hp.com!samsung!uunet!allbery Fri Jun 15 19:37:07 PDT 1990
Article 1641 of comp.sources.misc:
Path: bacchus.pa.dec.com!decwrl!elroy.jpl.nasa.gov!sdd.hp.com!samsung!uunet!allbery
From: cowan@marob.masa.com (John Cowan)
Newsgroups: comp.sources.misc
Subject: v13i046: FTPget: retrieve files by FTP from non-FTP Unix sites
Message-ID: <93333@uunet.UU.NET>
Date: 15 Jun 90 22:58:27 GMT
Sender: allbery@uunet.UU.NET
Organization: ESCC,  New York City
Lines: 145
Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)

Posting-number: Volume 13, Issue 46
Submitted-by: cowan@marob.masa.com (John Cowan)
Archive-name: ftpget/part01

#!/bin/sh
# FTPget version 1.0 by cowan@marob.masa.com (John Cowan)

# This shell script, which will work with either the Bourne or the Korn
# shell (it uses only V7 Bourne features), provides an interface to a
# mail-based FTP server.  Such a server allows Unix users who are not
# on the Internet to retrieve files from Internet machines by FTP.
# NOTE: THE SERVER ADDRESS IS NOT PROVIDED; IT MUST BE OBTAINED ELSEWHERE.
# To use FTPget, the local site must have an RFC-822 compliant mailer
# such as sendmail or smail which is capable of generating a correct From:.

# To configure FTPget, set up the SERVER= and MAIL= lines as follows:
#	SERVER=mailaddr sets the server mailing address
#	MAIL=pathname sets the pathname of your mailer (typically /bin/mail)
#	The settings below are useful for testing only.

SERVER="-"
MAIL="/bin/cat"

USER="anonymous"
PASSWD=""
ACCT=""
MODE="GUESS"

trap 'rm -f /tmp/ftpget.$$; exit 0' 0 1 2 3 4 5 6 7 8 9 10 12 13 14 15

if [ $# = 0 ]
then echo >&2 \
"usage:	$0 host [-u user] [-p pass] [-a acc] [-t | -b | -d dir | -l | file]*"
echo >&2 "	$0 -h (for help)"
echo >&2 "	$0 -H (for server help)"
echo >&2 "	$0 -L (for list of hosts)"
exit 1
fi

if [ $1 = "-h" ]
then cat <<!
The $0 program allows you to use the Internet's FTP
(file transfer protocol) facility even though you are not
on the Internet.  This is done via mailing to an FTP server
located at $SERVER.

To obtain a file by FTP, you need to know the host, or computer
on which the file resides.  You also need to know the pathname
of the file on that system.  The simplest way to retrieve files
is to use the command:
	$0 host files ...
Any number of files may be specified in the command.  Wild cards are
NOT usable, and will probably not do the right thing if you do specify them.

This simple method only works if the file is accessible "for anonymous FTP".
If anonymous FTP is not available at the host you want, you need to
have a login at the host, with username and password (and possibly
account, on some non-Unix hosts).  You can specify this to $0 with:
	$0 host -u user -p password -a account files ...
The -p and -a specifications are optional.

When FTP-ing files, it is necessary to specify whether they are text files
or binary files (compressed files are binary).  The $0 program tries to
guess a file's type from its name, but this guessing can be overridden by
using the -t (text) or -b (binary) options before the file name.  These
options are "sticky" and persist until the next -t or -b.

You can specify a directory for the interpretation of file names by using
the -d option.  Otherwise, file names are taken to be relative to the
"main" public directory of the host.  You can list the contents of a directory
specified with the -d option by using the -l option.  This listing may or
may not look like Unix's "ls -l".

Files requested are returned in one or more mail messages containing uuencoded
data.  Save the messages into files and use "uudecode".  This will generate
a file with some random all-upper-case name assigned by $SERVER.
Rename it to the correct name for the file you requested.  You can then discard
the uuencoded version.

For more information on this program, contact cowan@marob.masa.com.
!
exit 0
fi

if [ $1 = "-H" ]
then $MAIL $SERVER <<!
HELP
!
exit 0
fi

if [ $1 = "-L" ]
then $MAIL $SERVER <<!
FTPLIST
!
exit 0
fi

HOST=$1; shift
if [ x$1 = "x-u" ]
then USER=$2; shift; shift
fi

if [ x$1 = "x-p" ]
then PASSWD=$2; shift; shift
fi

if [ x$1 = "x-a" ]
then ACCT=$2; shift; shift
fi

exec 5>/tmp/ftpget.$$
echo >&5 "FTP $HOST UUENCODE"
echo >&5 "USER $USER $PASSWD"
if [ x$ACCT != "x" ]
then echo >&5 "ACCT $ACCT"
fi

while [ $# != 0 ]
do
	case $1 in
	-t)	MODE="ASCII"; shift; continue;;
	-b)	MODE="BINARY"; shift; continue;;
	-d)	echo >&5 "CD $2"; shift; shift; continue;;
	-l)	echo >&5 "LS"; shift; continue;;
	-*)	echo >&2 "$0: bad option $1"; exit 1;;
	*.Z|*.zoo|*.arc|*.zip|*.cpio|*.tar)
		GUESS="BINARY";;
	*)	GUESS="ASCII";;
	esac
	if [ $MODE = "GUESS" ]
	then echo >&2 "$0: $1 assumed $GUESS"
	else GUESS=$MODE
	fi
	echo >&5 $GUESS
	echo >&5 "GET $1"; shift
done
echo >&5 "QUIT"
exec 5>&-
$MAIL $SERVER </tmp/ftpget.$$
echo >$2 "Request sent"
exit 0
-- 
cowan@marob.masa.com			(aka ...!hombre!marob!cowan)
			e'osai ko sarji la lojban


