nsyed has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I am trying get the list of the remote ftp server dir. Problem is I dont know how to use "ls -l" or "ls -lR" command so that I can see the detail dir info. The code below works for "ls" only and if i use "ls -l" then i get syntax error. please help. Thanks
use Net::FTP::Common; $FTP_connect = { Host => "some.ftpserver.com", User => "someuser", Pass => "somepassword", RemoteDir => "/home/somedir/dest" } ; $ftp = Net::FTP::Common->new($FTP_connect); my @dircontents = $ftp->ls ; foreach(@dircontents) { print"$_\n"; } $ftp->quit;

Replies are listed 'Best First'.
Re: FTP Remote Dir listing
by Limbic~Region (Chancellor) on Oct 21, 2003 at 21:43 UTC
    nsyed,
    I have never used Net:FTP::Common, but from the docs:

    $ez->dir (%override) When given no arguments, dir() uses Common configuration information t +o login to the ftp site, change directory and transfer type and then +return a hash of with detailed description of directory contents. You + may only call this routine and expect a hash back. my %retval = $ez->dir;
    The hash will have keys like owner, size, etc that you can use to get the information you want

    Cheers - L~R

Re: FTP Remote Dir listing
by princepawn (Parson) on Oct 21, 2003 at 23:04 UTC
    Hi nsyed!!!

    First I must thank you for using my module. Second, I must say I would have seen your problem earlier if it had been mailed to the official support channel but anyway here I am!

    You are trying to retrieve an array from a function which returns a hash. You should get back the hash:

    my %dir = $ftp->ls
    And then iterate over it:
    for my $filename (keys %dir) { print $filename{perm}, "\n"; }

    Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality.