electricfork

Net::FTP::Recursive

Posted Nov 16, 08:09 AM by ben

I had some issues trying to use Net::FTP::Recursive yesterday. Turns out that it only understands UNIX style ls listings so when trying to rget from an FTP site with DOS formatted then it chokes silently. Lots of various questions on this but no answers that I found while googling. The pod does mention something about ParseSub but you have to pay attention to what they're talking about. ParseSub argument lets you add your own formatting input to allow the module to know how to parse the output. It's all very straightforward once you read the source.... If you're looking for why rget isn't working, check to see if your FTP site isn't using DOS style listings. If it is, feel free to use this:
$ftp->rget(ParseSub => &somesub);

sub somesub {

my @returnedobjs = ();
foreach my $line (@_) {
#print "file: $line";
my (@fields, $file);
$line =~ /^
d{1,2}-d{1,2}-d{1,2}s+ #date
d{1,2}:d{1,2}wws+ #time of day nn:nn{AM|PM}
(|d*)s+ #either DIR or filesize
(S*) #name of entry
$
/x;
$fields[6] = $2;

if (isDat($fields[6])) { $datfile = $fields[6]; }
next if $fields[6] =~ /^.{1,2}$/;
if ($1 eq '') {

$file = Net::FTP::Recursive::File->new(IsDirectory=>
1, IsPlainFile => 0,
IsSymlink => 0,
OriginalLine => $line,
Fields => [@fields]);
}

else {

$file = Net::FTP::Recursive::File->new(IsDirectory => 0,
IsPlainFile => 1,
IsSymlink => 0,
OriginalLine => $line,
Fields => [@fields]);
}

push(@returnedobjs, $file);
} return(@returnedobjs);

}
Delicious Digg Reddit Facebook Stumbleupon
// :: /

Commenting is closed for this article.

Creative Commons License
This work by http://electricfork.com is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.

archive

about

charmsec

I lead an information security ops and response team. This site is a collection of interesting notes and brainstorms on the protecting from, detecting of, and responding to badness. You can read more about me or my site here.

You can subscribe to my blog via rss , or if you're looking for older items check out my archive of previous posts.

I organize a small infosec meetup in baltimore called charmsec. If you are looking for charmsec details you probably want to go here.

 

RSS

:: © 2002-2008