set +x
#
# jftp -> Shell script for sending ascii files by ftp.
#         You must be in the same directory as the file to be ftp'ed.
#
# Usage : jftp ip-address file-to-be-sent
#                 $1           $2
#
# John Roebuck - 11/09/97
# John Roebuck - 11/01/99 - Remove all MTMS options and requirements.
#
version="jftp 1.1 by John Roebuck 11/01/99"

if [ $# != 2 ]
   then echo "Usage : jftp ip-address file-to-be-set"
        echo "        ("$version")"
        exit
fi

#
# set -f stops * being expanded.
#
set -f    

today=`date +%d/%m/%y`
now=`date +%H:%M:%S`

tempfile=/tmp/jftp-`date +%d%m%y%H%M%S`$$
touch $tempfile

#
# Get sender details eg user name and description, machine hostname
#
# sender login is the login name of the current user account
#
senderlogin=`whoami`
#
# Domain is taken from the domain field in /etc/resolv.conf file
#
senderdomain=`grep domain /etc/resolv.conf | cut -f2`
#
# Sender address is login name @ machine hostname . domain
#
senderaddress=$senderlogin"@"`hostname`"."$senderdomain

#
# Create a .netrc file for the ftp transfer
#

echo "#.netrc - created automatically by jftp on "$today" at "$now >> $tempfile

echo "#         "$version >> $tempfile
echo "#" >> $tempfile
echo "machine "$1" login anonymous password "$senderaddress >> $tempfile
echo "macdef init" >> $tempfile
echo "ascii" >> $tempfile
echo "mput "$2 >> $tempfile
echo "quit\n" >> $tempfile

#
#  Copy the $tempfile to $HOME/.netrc
#

cp $tempfile $HOME/.netrc
chmod 600 $HOME/.netrc

#
# Check if the PC is connected to the network.
# (verify range to target, one ping !)
# 

ping "$1" 64 1

if [[ $? -eq 0 ]]
   then ftp -iv "$1"
   else echo "***************"
        echo "*** WARNING *** "$1" is not responsing <- FTP aborted"
        echo "***************"
fi

rm $tempfile

