home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/perl/perl -s
-
- #
- # Get a file using ftp.
- #
- # ftpget host source dest
- # gets file, logging in as anonymous with user@host password (default)
- # ftpget user@host source dest
- # gets file as user "user" and prompts for password
- #
- # if "dest" is a directory, filename is same as remote file name
- #
- # Written by Gene Spafford <spaf@cs.purdue.edu>
- # Last update, 24 April 1992
- #
-
- unshift(@INC, "/homes/spaf/lib/perl");
- require "ftplib.pl";
-
-
- die "usage: ftpget [-ascii] <host> <source> <dest>
- where <host> may be of the form user@host
- user defaults to 'anonymous' if not specified
- " unless $#ARGV == 2;
-
- ($Host, $Source, $Dest) = @ARGV;
-
- if ($Host =~ /^(\S+)@(\S+)$/) { # user@host format?
- ($User, $Host) = ($1, $2);
- print STDERR "Password to use: ";
- system 'stty -echo';
- chop($Pass = <STDIN>);
- system 'stty echo';
- print STDERR "\n";
- }
-
- if ( -d $Dest) { # is it a directory?
- local($tmp) = ($Source);
- $tmp =~ s#.*/##;
- $Dest .= "/$tmp";
- }
-
- &ftp'open($Host, $User, $Pass) || &fail;
- &ftp'type($ascii ? "a" : "i") || &fail;
- &ftp'get($Source, $Dest) || &fail;
- &ftp'close;
-
-
- sub fail {
- $save = &ftp'error;
- &ftp'close;
- die $save;
- }
-