home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / scripts-convex / ftp.shar / ftp / ftpget next >
Encoding:
Text File  |  1992-08-17  |  1.2 KB  |  54 lines

  1. #!/usr/local/perl/perl -s
  2.  
  3. #
  4. #  Get a file using ftp.
  5. #
  6. #   ftpget host source dest
  7. #      gets file, logging in as anonymous with user@host password (default)
  8. #   ftpget user@host source dest
  9. #      gets file as user "user" and prompts for password
  10. #
  11. #   if "dest" is a directory, filename is same as remote file name
  12. #
  13. #  Written by Gene Spafford  <spaf@cs.purdue.edu>
  14. #   Last update, 24 April 1992
  15. #
  16.  
  17. unshift(@INC, "/homes/spaf/lib/perl");
  18. require "ftplib.pl";
  19.  
  20.  
  21. die "usage: ftpget [-ascii] <host> <source> <dest>
  22.     where <host> may be of the form user@host
  23.     user defaults to 'anonymous' if not specified
  24. " unless $#ARGV == 2;
  25.  
  26. ($Host, $Source, $Dest) = @ARGV;
  27.  
  28. if ($Host =~ /^(\S+)@(\S+)$/) {   # user@host format?
  29.     ($User, $Host) = ($1, $2);
  30.     print STDERR "Password to use: ";
  31.     system 'stty -echo';
  32.     chop($Pass = <STDIN>);
  33.     system 'stty echo';
  34.     print STDERR "\n";
  35.  
  36. if ( -d $Dest) {        # is it a directory?
  37.     local($tmp) = ($Source);
  38.     $tmp =~ s#.*/##;
  39.     $Dest .= "/$tmp";
  40. }
  41.  
  42. &ftp'open($Host, $User, $Pass) || &fail;
  43. &ftp'type($ascii ? "a" : "i") || &fail;
  44. &ftp'get($Source, $Dest) || &fail;
  45. &ftp'close;
  46.  
  47.  
  48. sub fail {
  49.     $save = &ftp'error;
  50.     &ftp'close;
  51.     die $save;
  52. }
  53.