Hi Confrere, I have a problem with the module Net::Ftp. I want to see the files on a FTP server. I can connect to servers but I do not get the listing of files within a dir.
use Net::FTP; my $FtpHost = "ftp.ncbi.nih.gov"; my ($ftp, $user, $password); # the destination directory my $NewCwd = "/genomes/Bacteria"; # listing of the directories, and sorted listing my (@DirList, @sorted); print "Logging in to $FtpHost.\n"; print "Logging in now.\n"; my $ftp = Net::FTP->new($FtpHost); $user = "anonymous"; $password = "murcia\@home.de"; if( $ftp->login($user, $password) != 1 ){ die "Can't login to $FtpHost\n"; } print "Logged in.\n"; print "Logged in to $FtpHost.\n"; # the present working directory my $Pwd; # get the current working directory if ( ($Pwd = $ftp->pwd) eq "" ) { die "Can't get current directory\n"; } else { print "pwd = $Pwd\n"; } # changing pwd to $NewCwd and then log it $ftp->cwd($NewCwd) || die "Can't cwd to $NewCwd\n"; $Pwd = $ftp->pwd; print "cd $NewCwd\n"; print "pwd = $Pwd\n"; # Returns a reference to a list of contents of the directory print "Retrieving entries in $Pwd\n"; if ((@DirList = $ftp->ls("*")) eq "") { die "Nothing found in the directory $NewCwd\n"; } print "@DirList\n";
STDOUT:
Logging in to ftp.ncbi.nih.gov. Logging in now. Logged in. Logged in to ftp.ncbi.nih.gov. pwd = / cd /genomes/Bacteria pwd = /genomes/Bacteria Retrieving entries in /genomes/Bacteria EOF

I tested this script on different computers with Linux OS with different perl versions (5.8.x).

$ftp->dir() does give also no results ...

And I tested different server e.g "ftp.suse.com"
Any hints?
Murcia

In reply to Net::ftp listing problem by Murcia

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.