home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / src / gopher / gopher1.01 / misc / gopher2ftp / g2ftpd next >
Text File  |  1992-02-10  |  3KB  |  91 lines

  1. #!/usr/local/bin/perl
  2. # Let's just call this version 0.1   A good first cut....
  3. #----Stuff here must be customized for your machine----
  4. $myName = "mudhoney.micro.umn.edu";       #host full domain name
  5. $myPort = "7997";            #port at which inetd is listening
  6. $ftp = "/usr/ucb/ftp";            #whereever on your box this lives
  7. #----end local customizations-------
  8.  
  9. #Hmm.  I'm really not sure how to catch signals...
  10. $SIG{'INT'} = 'CLEANUP';
  11. $SIG{'HUP'} = 'CLEANUP';
  12. $SIG{'QUIT'} = 'CLEANUP';
  13. $SIG{'PIPE'} = 'CLEANUP';
  14. $SIG{'ALRM'} = 'CLEANUP';
  15.  
  16. $tmp = "/tmp/gf$$";            #I'll clean up; Promise!
  17. $tmpData = "/tmp/gfd$$";        #This one's for spooling
  18. $separator = "@";            #For encoding selector with hostname
  19. $host = "";
  20. $getBinary = "";
  21. $query = <>;
  22. chop($query);
  23. chop($query);
  24. if ($query eq "") {
  25.     print "4 Incorrectly specified request for FTP (No hostname)\r\n.\r\n";
  26.     exit; 
  27. }
  28. ($host, $thing) = split(/@/, $query, 2);
  29. $thing = "/" if ($thing eq "");
  30. open(FTP, "| $ftp -n $host >$tmp") || die "4 Error. Couldn't connect to server";
  31. print FTP "user anonymous gopher@$myName\n";
  32. $thing2 = $thing;
  33. $dir = chop($thing2);
  34. if ($dir eq "/") {        #asking for a dir
  35.     print FTP "cd $thing2\n" if ($thing2 ne "");
  36.     print FTP "ls -F\n";
  37.     $tmpData = "";
  38. } else  {            #asking for a file 
  39.     $thing = $thing2 if $dir eq "*";
  40.     $getBinary = $thing =~ /\.(ZIP)|(ZOO)|(ARJ)|(ARC)|(LZH)|(HYP)|(PAK)|(EXE)|(TAR)|Z$/i;    #ick ick ick
  41.     print FTP "binary\n" if $getBinary ne "";
  42.     print FTP "get $thing $tmpData\n"; 
  43. }
  44. print FTP "quit\n";
  45. close(FTP);        #re-use the fileHandle
  46. if ($tmpData eq "") {    #maybe use an exists instead?
  47.     open(FTP, "$tmp") || die "4 Error. Could not return list.\r\n";
  48.     while (<FTP>) {
  49.         chop;
  50.         s/\*$//;            #Hack out stars
  51.         s&\@$&/&;            #Hack out ats
  52.         if  (s%/$%%) {            #It's a directory
  53.             print "1$_\t$host$separator$thing$_/";
  54.         } elsif (/\.HQX$/i) {    #binhex file
  55.             print "4$_\t$host$separator$thing$_";
  56.         } elsif (/\.(ZIP)|(ZOO)|(ARJ)|(ARC)|(LZH)|(HYP)|(PAK)|(EXE)$/i) {    #DOS scrap
  57.             print "5$_\t$host$separator$thing$_";
  58.         } elsif (/\.(TAR)|Z$/i) {    #we'll let these thru as 9
  59.             print "9$_\t$host$separator$thing$_";
  60.         } else {            #Regular text file
  61.             print "0$_\t$host$separator$thing$_";
  62.         }
  63.         print "\t$myName\t$myPort\r\n";
  64.     }
  65.     print ".\r\n";
  66. } elsif ($getBinary) {
  67.     open(FTP, "$tmpData") || die "4 Error.  Could not transfer file.\r\n";
  68.     while (<FTP>) {
  69.         print "$_";
  70.     }
  71. } elsif (-T $tmpData) { 
  72.     open(FTP, "$tmpData") || die "4 Error. Could not transfer file.\r\n";
  73.     while (<FTP>) {
  74.         chop;
  75.         print "$_\r\n";
  76.     }
  77.     print".\r\n";
  78. } else {
  79.     print "4 Sorry.  Requested file did not appear to contain text.\r\n.\r\n";
  80. }
  81. close(FTP);
  82. unlink("$tmp");
  83. unlink("$tmpData") if ($tmpData ne "");
  84. exit;
  85.  
  86. sub CLEANUP {
  87.     print "4 Error in FTP transaction.\r\n.\r\n";
  88.     unlink("$tmp");
  89.     unlink("$tmpData") if ($tmpData ne "");
  90. }
  91.