Monks, I bow to your Buddha Nature.

I have written a script to generate a web page that lists the contents of an FTP site. It has to recurse through all the directories and sub directories like so:
#! /usr/bin/perl -w use strict; use Net::FTP; my $ftp = Net::FTP->new("ftp address here"); print "Content-type: text/html\n\n"; print "<html><title>FTP Contents</title><center><Head>The Tank FTP Lis +t</head></ print "<body bgcolor=black>"; if($ftp->login("username",'password')){ lister(0); } else{ print "FTP: Failed to login"; } $ftp->quit; print "</body></html>"; #------Subroutines------------ sub lister{ my $lev = $_[0]; my @dirs; my @files; my @dirarray = $ftp->ls(); foreach my $item(@dirarray){ if($ftp->cwd($item)){ $ftp->cdup(); push @dirs,$item; } else{ push @files,$item; } } my $buff="&nbsp&nbsp&nbsp" x $lev; foreach my $dirs(@dirs){ print "<font color=yellow>$buff\|_ $dirs</font><br>"; $ftp->cwd($dirs); lister($lev+1); } foreach my $file(@files){ print "<font color=lime>$buff\|_ $file</font><br>"; } $ftp->cdup(); }
As you can see it basically takes the contents of a directory and puts them in either a directory array or a file array. It differentiates between the two by checking to see if the FTP->cwd("tested item") (change directory) works. It then takes everything in the directory array and recursivly calls itself on that directory. As is it works fine, but for large sites (4000+ files and driectores) it takes a LONG time, and is quite server transaction intensive. Is there a better way to do this? I looked in the NET::FTP docs and I don't see anything that really fits the bill. I would like to know if there is a way to read file attributes on an FTP site. Any one?

In reply to A better way to recurse FTP directories by Snuggle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.