ls in ftp fails

Discussion in 'Perl Misc' started by mike, May 19, 2010.

  1. mike

    mike Guest

    Hi,

    I connect to a remote ftp site:

    I see the following from the script:

    Directory is /mirror/eclipse/technology/epp/downloads/release/galileo/
    SR2

    I cannot list the files in the directory $current_dir.

    The line that fails is:

    my @files=$ftp -> ls("$current_dir") or die "Could not list files. $!
    \n";

    Any idea what I am doing wrong? All help is very much appreciated.

    //mike

    Code:
    use strict;
    use warnings;
    use Net::FTP;

    my $message;

    my $hostname ="ftp.ing.umu.se";

    my $remote_dir = "/mirror/eclipse/technology/epp/downloads/release/
    galileo/SR2/";

    my $ftp = Net::FTP -> new ($hostname,Timeout => 30,Debug => 0) or
    die "Cannot access $hostname via FTP\n";

    $ftp -> login("anonymous",'-anonymous@') or
    die "Invalid user name and/or password\n",$ftp-> $message;

    $ftp->binary();
    $ftp->cwd("$remote_dir") or die "Couldn't change directory. $!", $ftp->
    $message;
    my $current_dir = $ftp -> pwd();
    print ("Directory is $current_dir \n");

    my @files=$ftp -> ls("$current_dir") or die "Could not list files. $!
    \n";

    foreach my $file (@files){
    print "$file \n";
    }
    mike, May 19, 2010
    #1
    1. Advertising

  2. mike

    smallpond Guest

    Re: ls in ftp fails

    On May 19, 8:55 am, mike <> wrote:
    > Hi,
    >
    > I connect to a remote ftp site:
    >
    > I see the following from the script:
    >
    > Directory is /mirror/eclipse/technology/epp/downloads/release/galileo/
    > SR2
    >
    > I cannot list the files in the directory $current_dir.
    >
    > The line that fails is:
    >
    > my @files=$ftp -> ls("$current_dir") or die "Could not list files. $!
    > \n";
    >
    > Any idea what I am doing wrong? All help is very much appreciated.


    Yes. What you are doing wrong is not telling us what error got
    printed
    by the die, The whole point of the die instruction is to print out
    that informative little $! thingy.
    smallpond, May 19, 2010
    #2
    1. Advertising

  3. mike <> writes:

    > The line that fails is:
    >
    > my @files=$ftp -> ls("$current_dir") or die "Could not list files. $!
    > \n";


    In the documentation for Net::FTP I see no sign of $! having any
    significance to errors in the module. The synopsis have examples of
    error handling using $ftp->message. It might be more helpful.

    (Not that the message method is actually documentes. *sigh*)

    //Makholm
    Peter Makholm, May 19, 2010
    #3
  4. mike

    Guest

    On Wed, 19 May 2010 21:00:33 +0100, Big and Blue <> wrote:

    >On 05/19/10 13:55, mike wrote:
    >
    > > Any idea what I am doing wrong? All help is very much appreciated.

    >
    >Are you sure that is the code you are using...
    >
    > > $ftp -> login("anonymous",'-anonymous@') or
    > > die "Invalid user name and/or password\n",$ftp-> $message;

    ^^^^^^^^^^^^^^^^
    >
    >...since that line produces the error message:


    Yeah, look at that. Good eye!

    -sln
    , May 19, 2010
    #4
  5. mike

    Ohhhh maaan Guest

    mike wrote:

    > Hi,
    >
    > I connect to a remote ftp site:
    >
    > I see the following from the script:
    >
    > Directory is /mirror/eclipse/technology/epp/downloads/release/galileo/
    > SR2
    >
    > I cannot list the files in the directory $current_dir.
    >
    > The line that fails is:
    >
    > my @files=$ftp -> ls("$current_dir") or die "Could not list files. $!
    > \n";
    >


    Works for me, try setting PASV mode or not, because it's likely a
    firewall issue that's blocking the listing.
    Ohhhh maaan, May 19, 2010
    #5
  6. mike

    mike Guest

    Re: ls in ftp fails

    On 19 Maj, 22:06, Ohhhh maaan <> wrote:
    > mike wrote:
    > > Hi,

    >
    > > I connect to a remote ftp site:

    >
    > > I see the following from the script:

    >
    > > Directory is /mirror/eclipse/technology/epp/downloads/release/galileo/
    > > SR2

    >
    > > I cannot list the files in the directory $current_dir.

    >
    > > The line that fails is:

    >
    > > my @files=$ftp -> ls("$current_dir") or die "Could not list files. $!
    > > \n";

    >
    > Works for me, try setting PASV mode or not, because it's likely a
    > firewall issue that's blocking the listing.


    Thanks for all helpful pointers. I had a typo i my code. I was
    supposed to be message and not $message.

    //mike
    mike, May 20, 2010
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. someone

    FTP over SSL vs FTP over SSH

    someone, Apr 24, 2004, in forum: Java
    Replies:
    1
    Views:
    4,547
    iksrazal
    Apr 25, 2004
  2. Replies:
    3
    Views:
    5,583
  3. Nico Grubert
    Replies:
    0
    Views:
    612
    Nico Grubert
    Nov 24, 2005
  4. Nico Grubert
    Replies:
    0
    Views:
    428
    Nico Grubert
    Nov 25, 2005
  5. D. Buck
    Replies:
    2
    Views:
    448
    D. Buck
    Jun 29, 2004
Loading...

Share This Page