#!/usr/local/bin/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 # Last update, 17 May 1994 D. Sundstrom # require "ftplib.pl"; die "usage: ftpget [-ascii] where 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 = ); 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; }