home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3081 / mftp next >
Encoding:
Text File  |  1991-03-15  |  6.2 KB  |  252 lines

  1. #! /usr/local/bin/perl
  2. eval '(exit $?0)' && eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}' & eval 'exec /usr/local/bin/perl -S $0 $argv:q'
  3. if 0;
  4. #end of perlstart
  5. # NOTE ON PERLSTART:  ENSURE YOUR PERLPATH (/usr/.../perl) IS CORRECT FOR YOUR
  6. # SYSTEM.
  7. # SEE "EDIT THESE VALUES" BELOW.
  8.  
  9. # Perl Program mftp Clay Luther January 1991
  10. # Send comments to cluther@supernet.haus.com
  11.  
  12. # ABSTRACT:
  13. # Provide a simple interface to the mail ftp servers.
  14. #
  15. # DESCRIPTION:
  16. # mftp is a user interface to internet mail ftp services.  Mail ftp services
  17. # work by having the user submit a file containing standard FTP commands to
  18. # a mail ftp server.  The mail server performs the inet ftp connection to
  19. # the machine the user wants to ftp to and mails ftp output back to the
  20. # user.
  21. #
  22. # Mftp provides the user with a simple interface to a mail ftp server.  From
  23. # unix, the user enters the command "mftp [site] [user] [passwd]".  If he
  24. # does not enter "site", the mftp prompts him for one.  "User" and "passwd"
  25. # default to "anonymous".
  26. #
  27. # Mftp then presents the user with a simple menu of commands.  The user
  28. # enters a command by typing a letter followed by a carriage return.  If
  29. # the command takes a parameter, the user may enter it on the same line as
  30. # the command letter; otherwise, mftp will prompt the user for the parameter.
  31. #
  32. # Mftp builds a file containing the user's ftp requests.  Once the user is
  33. # finished entering commands, mftp mails the request file to the defined
  34. # mftp server (see variable $bitftp).
  35. #
  36. # If mftp encounters and error during execution, it dies with an appropriate
  37. # message.
  38.  
  39.  
  40. # mftp: a batched ftp program
  41. # USAGE: mftp [site] [user] [passwd]
  42.  
  43. #####################
  44. # EDIT THESE VALUES #
  45. $tmp = "/tmp/mftp$$";
  46. $version = "mftp version 1.0";
  47. $mail = "/usr/lib/sendmail";
  48. $edit = "/usr/bin/vi";
  49. $more = "/usr/local/bin/less";
  50. $bitftp = "bitftp@pucc.princeton.edu";
  51. ######################################
  52.  
  53.  
  54. ($site,$user,$passwd) = @ARGV;
  55.  
  56. if (!$site) {
  57.   print "open: ";
  58.   chop($site=<STDIN>);
  59. }
  60.  
  61. $user = "anonymous" unless $user;
  62. $passwd = "anonymous" unless $passwd;
  63.  
  64.  
  65. print "\n\nWelcome to $version.\nConnect to ftp server $site.\nUser $user, password $passwd.\n";
  66.  
  67. print "Batching commands to $tmp...\n";
  68. open(F,">$tmp") || die "Cannot open $tmp: $!\n";
  69. print F "FTP $site UUENCODE\n";
  70. print F "USER $user $passwd\n";
  71. close(F);
  72.  
  73. $dir = "";
  74. $mode = "ASCII";
  75. $atleastone = 0;
  76. $help = 0;
  77.  
  78. while (&quest) {
  79.   if ($atleastone >= 5) {    # Time to ship this baby...too many
  80.                                 # output commands
  81.     local($a);
  82.     print "You have entered $atleastone output requests.\n";
  83.     $atleastone = 0;
  84.     print "Send the current requests and continue [y]? ";
  85.     chop($a=<STDIN>);
  86.     $a = "y" unless $a;
  87.     if ($a =~ /y.*/i) {
  88.       # append QUIT
  89.       &frint("QUIT\n");
  90.       # send request
  91.       print "Mailing requests...\n";
  92.       system("$mail $bitftp < $tmp");
  93.       # reopen request batch
  94.       system("rm -f $tmp");
  95.       &frint("FTP $site UUENCODE\n");
  96.       &frint("USER $user $passwd\n"); 
  97.     }
  98.     else {
  99.       print "Quit mftp? ";
  100.       chop($a=<STDIN>);
  101.       if ($a =~ /y.*/i) {
  102.         goto quitmftp;
  103.       }
  104.     }
  105.   }
  106. } ;
  107.  
  108. quitmftp:
  109.  
  110. if ($atleastone) {
  111.   local($req);
  112.   if ($atleastone>1) { $req="s"; } else { $req=""; }
  113.   print "$atleastone output request$req.\n";
  114.   print "Sending the request to $bitftp...";
  115.   system("$mail $bitftp < $tmp");
  116.   print "\nYou should get a reply back within a day.\n";
  117. } else {
  118.   print "Hmm...no commands entered.  Not sending the request.\n";
  119. }
  120. system("rm -f $tmp");
  121.  
  122. exit 0;
  123.  
  124. ############## END OF MAIN ###############
  125.  
  126. sub quest
  127. {
  128.   local($c,$d);
  129.   print "\nMode: $mode";
  130.   if (length($dir)>0) {
  131.     print "\tLast Chdir: $dir";
  132.   }
  133.   print "\n";
  134.   if ($help) {
  135.     print "A)scii B)inary C)hdir D)ir E)dit F)orget G)et H)elp Q)uit V)iew Z)ap\n";
  136.     $help=0;
  137.   }
  138.   print "[abcdeghqvz?]: ";
  139.   chop($c = <STDIN>);
  140.   if ($c =~ /^ *a.*/i) {
  141.     $mode = "ASCII";
  142.     &frint("$mode\n");
  143.     return 1;
  144.   }
  145.   elsif ($c =~ /^ *b.*/i) {
  146.     $mode = "BINARY";
  147.     &frint("$mode\n");
  148.     return 1;
  149.   }
  150.   elsif ($c =~ /^ *c.*/i) {
  151.     local(@P) = split(' ',$c);
  152.     shift(@P);
  153.     $c = join(' ',@P);
  154.     if ($c) {
  155.       $d = $c;
  156.     } else {
  157.       print "Chdir to: ";
  158.       chop($d = <STDIN>);
  159.     }
  160.     $dir = $d;
  161.     &frint("CD $d\n"); 
  162.     return 1;
  163.   }
  164.   elsif ($c =~ /^ *d.*/i) {
  165.     local(@P) = split(' ',$c);
  166.     shift(@P);
  167.     $c = join(' ',@P);
  168.     if ($c) {
  169.       $d = $c;
  170.     } else {
  171.       print "Dir of: ";
  172.       chop($d = <STDIN>);
  173.     }
  174.     &frint("DIR $d\n");
  175.     $atleastone++;
  176.     return 1;
  177.   }
  178.   elsif ($c =~ /^ *e.*/i) {
  179.     system("$edit $tmp");
  180.     return 1;
  181.   }
  182.   elsif ($c =~ /^ *f.*/i) {
  183.     $atleastone = 0;
  184.     return 0;
  185.   }
  186.   elsif ($c =~ /^ *g.*/i) {
  187.     local(@P) = split(' ',$c);
  188.     shift(@P);
  189.     $c = join(' ',@P);
  190.     if ($c) {
  191.       $d = $c;
  192.     } else {
  193.       print "Get file: ";
  194.       chop($d = <STDIN>);
  195.     }
  196.     &frint("GET $d\n");
  197.     $atleastone++;
  198.     return 1;
  199.   }
  200.   elsif ($c =~ /^ *q.*/i) {
  201.     &frint("QUIT\n");
  202.     return 0;
  203.   }
  204.   elsif ($c =~ /^ *v.*/i) {
  205.     system("$more $tmp");
  206.     return 1;
  207.   }
  208.   elsif ($c =~ /^ *z.*/i) {
  209.     system("rm -f $tmp");
  210.     &frint("FTP $site UUENCODE\n");
  211.     &frint("USER $user $passwd\n");
  212.     $atleastone = 0;
  213.     $mode = "ASCII";
  214.     $dir = "";
  215.     return 1;
  216.   }
  217.   elsif ($c =~ /^ *\?.*/) {
  218.     $help = 1;
  219.     return 1;
  220.   } 
  221.   elsif ($c =~ /^ *h.*/i) {    # print some screen help
  222.     print "\n";
  223.     print "A)scii    Switch to ASCII file transfer mode.\n";
  224.     print "B)inary   Switch to BINARY file transfer mode.\n";
  225.     print "C)hdir    Change current directory.\n";
  226.     print "D)ir      List specified directory.\n";
  227.     print "E)dit     Edit current batch with $edit.\n";
  228.     print "F)orget   Abort this session.\n";
  229.     print "G)et      Get the specified file.\n";
  230.     print "H)elp     Show this.\n";
  231.     print "Q)uit     Stop batching and send the requests.\n";
  232.     print "V)iew     Show current batch with $more.\n";
  233.     print "Z)ap      Erase and restart current batch.\n";
  234.     print "?         Quick help.\n\n";
  235.     return 1;
  236.   }
  237.   else {
  238.     print "Unknown command: $c\n";
  239.     return 1;
  240.   } 
  241. }
  242.  
  243.  
  244. sub frint
  245. {
  246.   local($s) = @_;
  247.   open(F,">>$tmp") || die "Cannot open $tmp: $!\n";
  248.   print F $s;
  249.   print " > " . $s;
  250.   close(F);
  251. }
  252.