Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Recursion Over FTP

by Snuggle (Friar)
on Sep 27, 2002 at 14:58 UTC ( #201220=note: print w/replies, xml ) Need Help??


in reply to Recursion Over FTP

Well not to do it all for you but try something like this, it makes a webpage that shows the contents of a FTP site with links that work:
#! /usr/bin/perl -w use strict; use Net::FTP; my $ftp = Net::FTP->new("Address to ftp site); print "Content-type: text/html\n\n"; print "<html><title>FTP Contents</title>"; print "<body bgcolor=black text=white link=lime vlink=wheat>"; if($ftp->login("Username", 'password')){ lister(0,"ftp://toplevel/"); } else{ print "FTP: Failed to login"; } $ftp->quit; print "</body></html>"; #----subs---- sub lister{ my $lev = shift; my $path = shift; 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&nbsp&nbsp" x $lev; foreach my $dirs(@dirs){ print "<font color=yellow>$buff\|_ $dirs</font><br>"; $ftp->cwd($dirs); lister($lev+1,$path."/".$dirs); } foreach my $file(@files){ print "<font color=lime>$buff\|_ <a href=\"$path/$file +\">$file</a></font><br>"; } $ftp->cdup(); }

Try looking at this seeing what I am doing. Basically, it checks the dir of a directory, splits the objects into directories and files, and recurses into the directories. Hope it helps.
Anyway, no drug, not even alcohol, causes the fundamental ills of society. If we're looking for the source of our troubles, we shouldn't test people for drugs, we should test them for stupidity, ignorance, greed and love of power.

--P. J. O'Rourke

Replies are listed 'Best First'.
Re: Re: Recursion Over FTP
by jmaya (Acolyte) on Oct 03, 2002 at 22:27 UTC
    Awesome This is exactly what i wanted... I learned alot thankz

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://201220]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2022-12-08 03:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?