Well, the wget is a solution to what I needed to do, and works fine, but for myself, I'm still trying to figure it out with Net::FTP. This is what I have so far as far as code goes:
#!/usr/bin/perl
use warnings;
use strict;
use Net::FTP;
my $ftp; #Net::FTP object
my $is_error = 0;
my $conn_success = 0;
print "<?>~ Enter FTP Host: ";
my $hostname = <STDIN>;
chomp($hostname);
while($conn_success != 1) {
$ftp = Net::FTP->new($hostname,Timeout => 60, Passive => 1) or
+ $is_error = 1;
if($is_error){
print "<!>~ Couldn't connect to $hostname.";
}
print "\n<->~ Connected to $hostname";
print "\n<?>~ Enter FTP username: ";
my $username = <STDIN>;
chomp($username);
print "\n<?>~ Enter FTP password: ";
my $password = <STDIN>;
chomp($password);
print "Trying to connect with\n <->Username: $username\n <->Pa
+ssword: $password\n";
$ftp->login("$username","$password") or $is_error = 1;
if($is_error){
print "\n<!>~ Login Failed!\n";
}
else {
print "<->~ Login Successful\n";
}
$is_error = 0;
$conn_success = 1;
}
$ftp->binary;
file_dload($ftp->ls);
$ftp->quit;
sub file_dload
{
my @files = @_;
foreach my $file(@files){
$ftp->get($file);
#insert recursion for directories here
}
}
My biggest hurdle here is I can't figure out how to code it so the ftp connection differentiates between the directories. I was thinking of using $ftp->dir and regular expressions to match entries that start with drwx, etc. But I'm not sure how I would cut that entry in my array from
drwxr-xr-x 12 owner group 1536 Aug 4 13:07 dir_name
to just have the dir_name, then I could just $ftp->cwd(dir_name) and start the recursive call to the subroutine | [reply] [d/l] |