# --------------------------------------------------
# mirror - mirrors an internet site using FTP
# --------------------------------------------------
# by Craig Comstock 1998
# --------------------------------------------------

use Net::FTP;
use File::Listing;

# subroutine mirror is a recursive function
# mirror ($depth, $path, $target) 
# it parses and downloads files
# $depth = how deep into the directory tree you want to go
# (1 is simply the current directory)
# $path = root path to start from
# $target = local root path to mirror to

sub mirror {
	my $depth = shift(@_);
	my $path = shift(@_);
	my $target = shift(@_);
	
	#status line
	print "$depth - $path - $target\n";

	if ($depth == 0) {return;}

	for (parse_dir($ftp->dir($path))) {
	    ($name, $type, $size, $mtime, $mode) = @$_;
		if (($type eq 'd') && ($name ne '$pfebk')) {
			mkdir($target."/".$name,777);
			mirror($depth-1,$path."/".$name,$target."/".$name);
			next;
		}
		elsif ($type eq 'f') 
		{
			print "getting $path/$name to $target/$name\n";
			$ftp->get($path."/".$name,$target."/".$name);
		}
	}
}


#login to the server we want to go to

$ftp = Net::FTP->new("hostname");
$ftp->login("username","password");

#select which path to start with
$path = '/';

#set type as binary
$ftp->binary();

#execute function
#localpath should start "c:\\" for dos/win
#                    or "/" for unix...
mirror(1,$path,"localpath");

#logout
$ftp->quit;

#that's it
end;
Make your own free website on Tripod.com