cluther@supernet.dallas.haus.com (Clay Luther) (03/15/91)
Here is MFTP, a simple program written in Perl that provides a nice interface
to the bitftp server (or any mail server with a little modification) to sites
that do not have full-ip access.
Enjoy.
#! /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 the files:
# README
# mftp
# This archive created: Thu Mar 14 22:08:37 1991
export PATH; PATH=/bin:$PATH
if test -f 'README'
then
echo shar: will not over-write existing file "'README'"
else
cat << \SHAR_EOF > 'README'
MFTP - Mail FTP Client
by Clay Luther
Copyright 1991, Clay Luther
This is Freeware.
Send comments to cluther@supernet.haus.com.
After unsharing the file, edit it and change the values indicated by the
keywords NOTE and EDIT.
Have fun.
SHAR_EOF
chmod +x 'README'
fi # end of overwriting check
if test -f 'mftp'
then
echo shar: will not over-write existing file "'mftp'"
else
cat << \SHAR_EOF > 'mftp'
#! /usr/local/bin/perl
eval '(exit $?0)' && eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}' & eval 'exec /usr/local/bin/perl -S $0 $argv:q'
if 0;
#end of perlstart
# NOTE ON PERLSTART: ENSURE YOUR PERLPATH (/usr/.../perl) IS CORRECT FOR YOUR
# SYSTEM.
# SEE "EDIT THESE VALUES" BELOW.
# Perl Program mftp Clay Luther January 1991
# Send comments to cluther@supernet.haus.com
# ABSTRACT:
# Provide a simple interface to the mail ftp servers.
#
# DESCRIPTION:
# mftp is a user interface to internet mail ftp services. Mail ftp services
# work by having the user submit a file containing standard FTP commands to
# a mail ftp server. The mail server performs the inet ftp connection to
# the machine the user wants to ftp to and mails ftp output back to the
# user.
#
# Mftp provides the user with a simple interface to a mail ftp server. From
# unix, the user enters the command "mftp [site] [user] [passwd]". If he
# does not enter "site", the mftp prompts him for one. "User" and "passwd"
# default to "anonymous".
#
# Mftp then presents the user with a simple menu of commands. The user
# enters a command by typing a letter followed by a carriage return. If
# the command takes a parameter, the user may enter it on the same line as
# the command letter; otherwise, mftp will prompt the user for the parameter.
#
# Mftp builds a file containing the user's ftp requests. Once the user is
# finished entering commands, mftp mails the request file to the defined
# mftp server (see variable $bitftp).
#
# If mftp encounters and error during execution, it dies with an appropriate
# message.
# mftp: a batched ftp program
# USAGE: mftp [site] [user] [passwd]
#####################
# EDIT THESE VALUES #
$tmp = "/tmp/mftp$$";
$version = "mftp version 1.0";
$mail = "/usr/lib/sendmail";
$edit = "/usr/bin/vi";
$more = "/usr/local/bin/less";
$bitftp = "bitftp@pucc.princeton.edu";
######################################
($site,$user,$passwd) = @ARGV;
if (!$site) {
print "open: ";
chop($site=<STDIN>);
}
$user = "anonymous" unless $user;
$passwd = "anonymous" unless $passwd;
print "\n\nWelcome to $version.\nConnect to ftp server $site.\nUser $user, password $passwd.\n";
print "Batching commands to $tmp...\n";
open(F,">$tmp") || die "Cannot open $tmp: $!\n";
print F "FTP $site UUENCODE\n";
print F "USER $user $passwd\n";
close(F);
$dir = "";
$mode = "ASCII";
$atleastone = 0;
$help = 0;
while (&quest) {
if ($atleastone >= 5) { # Time to ship this baby...too many
# output commands
local($a);
print "You have entered $atleastone output requests.\n";
$atleastone = 0;
print "Send the current requests and continue [y]? ";
chop($a=<STDIN>);
$a = "y" unless $a;
if ($a =~ /y.*/i) {
# append QUIT
&frint("QUIT\n");
# send request
print "Mailing requests...\n";
system("$mail $bitftp < $tmp");
# reopen request batch
system("rm -f $tmp");
&frint("FTP $site UUENCODE\n");
&frint("USER $user $passwd\n");
}
else {
print "Quit mftp? ";
chop($a=<STDIN>);
if ($a =~ /y.*/i) {
goto quitmftp;
}
}
}
} ;
quitmftp:
if ($atleastone) {
local($req);
if ($atleastone>1) { $req="s"; } else { $req=""; }
print "$atleastone output request$req.\n";
print "Sending the request to $bitftp...";
system("$mail $bitftp < $tmp");
print "\nYou should get a reply back within a day.\n";
} else {
print "Hmm...no commands entered. Not sending the request.\n";
}
system("rm -f $tmp");
exit 0;
############## END OF MAIN ###############
sub quest
{
local($c,$d);
print "\nMode: $mode";
if (length($dir)>0) {
print "\tLast Chdir: $dir";
}
print "\n";
if ($help) {
print "A)scii B)inary C)hdir D)ir E)dit F)orget G)et H)elp Q)uit V)iew Z)ap\n";
$help=0;
}
print "[abcdeghqvz?]: ";
chop($c = <STDIN>);
if ($c =~ /^ *a.*/i) {
$mode = "ASCII";
&frint("$mode\n");
return 1;
}
elsif ($c =~ /^ *b.*/i) {
$mode = "BINARY";
&frint("$mode\n");
return 1;
}
elsif ($c =~ /^ *c.*/i) {
local(@P) = split(' ',$c);
shift(@P);
$c = join(' ',@P);
if ($c) {
$d = $c;
} else {
print "Chdir to: ";
chop($d = <STDIN>);
}
$dir = $d;
&frint("CD $d\n");
return 1;
}
elsif ($c =~ /^ *d.*/i) {
local(@P) = split(' ',$c);
shift(@P);
$c = join(' ',@P);
if ($c) {
$d = $c;
} else {
print "Dir of: ";
chop($d = <STDIN>);
}
&frint("DIR $d\n");
$atleastone++;
return 1;
}
elsif ($c =~ /^ *e.*/i) {
system("$edit $tmp");
return 1;
}
elsif ($c =~ /^ *f.*/i) {
$atleastone = 0;
return 0;
}
elsif ($c =~ /^ *g.*/i) {
local(@P) = split(' ',$c);
shift(@P);
$c = join(' ',@P);
if ($c) {
$d = $c;
} else {
print "Get file: ";
chop($d = <STDIN>);
}
&frint("GET $d\n");
$atleastone++;
return 1;
}
elsif ($c =~ /^ *q.*/i) {
&frint("QUIT\n");
return 0;
}
elsif ($c =~ /^ *v.*/i) {
system("$more $tmp");
return 1;
}
elsif ($c =~ /^ *z.*/i) {
system("rm -f $tmp");
&frint("FTP $site UUENCODE\n");
&frint("USER $user $passwd\n");
$atleastone = 0;
$mode = "ASCII";
$dir = "";
return 1;
}
elsif ($c =~ /^ *\?.*/) {
$help = 1;
return 1;
}
elsif ($c =~ /^ *h.*/i) { # print some screen help
print "\n";
print "A)scii Switch to ASCII file transfer mode.\n";
print "B)inary Switch to BINARY file transfer mode.\n";
print "C)hdir Change current directory.\n";
print "D)ir List specified directory.\n";
print "E)dit Edit current batch with $edit.\n";
print "F)orget Abort this session.\n";
print "G)et Get the specified file.\n";
print "H)elp Show this.\n";
print "Q)uit Stop batching and send the requests.\n";
print "V)iew Show current batch with $more.\n";
print "Z)ap Erase and restart current batch.\n";
print "? Quick help.\n\n";
return 1;
}
else {
print "Unknown command: $c\n";
return 1;
}
}
sub frint
{
local($s) = @_;
open(F,">>$tmp") || die "Cannot open $tmp: $!\n";
print F $s;
print " > " . $s;
close(F);
}
SHAR_EOF
chmod +x 'mftp'
fi # end of overwriting check
# End of shell archive
exit 0
--
Clay Luther, Postmaster cluther@supernet.dallas.haus.com
Harris Adacom Corporation cluther@enigma.dallas.haus.com
Voice: 214/386-2356 MS 23, PO Box 809022, Dallas, Tx 75380-9022
Fax: 214/386-2159 Your mileage may vary. Void where prohibited.