#!/bin/sh

# rget --- get a file from a remote machine.  basically automated ftp.  
# very primitive, very dumb.

# first rev, mon, 7jun1999

TMPFILE=/tmp/ftpchat

REMOTEHOST=$1
REMOTEFILE=$2
LOCALFILE=$3

case $1 in
	-h|--help)
		echo
		echo "usage: $0 remotehost remotefile localfile"
		echo "     get a file from a remote machine."
		echo "     this is a very primitive substitute for rcp, which uses ftp as the "
		echo "     file transfer mechanism."
		echo
		echo "     a valid .netrc entry is required for remotehost."
		echo "     see the ftp(1) man page for info about .netrc."
		echo
		echo "     all arguments are required.  multiple file copy does not work."
		echo
		exit
		;;
esac

if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
	echo usage: $0 remotehost remotefile localfile
	echo a valid .netrc entry is required for remotehost
	exit
fi

# create the input for ftp
cat >$TMPFILE  <<EOF
get $REMOTEFILE $LOCALFILE
bye
EOF

# call ftp
ftp $REMOTEHOST < $TMPFILE

# clean up after yourself
rm $TMPFILE

