Perl FTP navigation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl FTP navigation
# 1  
Old 01-16-2011
Tools Perl FTP navigation

Hi Experts,

I have this requirement to list dirs and files of an FTP server on regular basis.
I was able to do it by following script:

Code:
$ftpobj = Net::FTP -> new ("$ftpsrv") || die "Cannot connect to FTP $ftpsrv";
$ftpobj -> login("user","passwd");
$ftpobj -> cwd ("/root_dir");
@rootdir = $ftpobj -> pwd();
print @rootdir , "\n";
@dirlist = $ftpobj -> ls();
foreach $fl (@dirlist){
@dlist = $ftpobj -> ls("/root_dir/$fl");
    foreach $f (@dlist){
        @dlistfin = $ftpobj -> ls("$f");
        print "\n----------------------------------------------------------------------------------------\n";
        print "$f \n";
        print "----------------------------------------------------------------------------------------\n";
        foreach $ffin (@dlistfin){
            print $ffin ,"\n";
    }
    }
    }

$ftpobj -> quit;


Script gives nice output and i am happy with it I want to take it to another level.
this script will list for all entries and is limited to only 2 levels.
I want to make it flexible, Like it can go as deep as nth dir and list complete path of files in that dir.

Requirement now is

1. How to check on FTP via perl if it is a file or dir.
2. If its a file just list file name.
3. if its a dir go list files/dir inside it and so and so ..

First step is to identify file type.
any clues.

thanks in advance.
# 2  
Old 01-16-2011
This is not an easy task to do reliably with all the different formats ls in FTP may output. Fortunately you can use the Net::FTP::Recursive module, its rdir call in particular to get what you want.
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. HP-UX

[Solved] Unable to rename file in ftp server .Net:FTP perl

Hello All, I am trying to connect to ftp server and get the files. Also i need to rename the file in other ftp dir. rename method is not allowing me to rename the file in other dir. When i tried copy command by using net::FTP:FILE then perl says it is not installed. Can some body help me to... (2 Replies)
Discussion started by: krsnadasa
2 Replies

2. Post Here to Contact Site Administrators and Moderators

Re: Suggestion to ease navigation .... thread

This post should be an edit of the post I just made to start the "Suggestion to ease navigation ..." thread, but my original post is not visible to edit, since it's waiting for moderator approval ... Additional text I wanted to add to my original post: The title of the The UNIX and Linux... (2 Replies)
Discussion started by: usnay12345
2 Replies

3. SuSE

Navigation of Fedora Core 6

Hi. Not sure if this should go in the beginners section, so forgivness please if it's not correctly placed. I just installed Linux Fedora Core 6 on my home computer (and am very very new to this) so I can learn more about it. However, I am looking for the FC6 equivalent to the System Device... (2 Replies)
Discussion started by: Carl1976
2 Replies

4. Shell Programming and Scripting

Navigation Toolkit for BASH

UNIX Forum, Please see the latest version of my navigation toolkit for BASH. The project web-page on SourceForge can found here: Bash Navigator Home Page (SourceForge) I would appreciate any input you might have. Regards (2 Replies)
Discussion started by: rlandon@usa.net
2 Replies
Login or Register to Ask a Question