Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Perl FTP problem Can't list files  (Read 4614 times)

0 Members and 1 Guest are viewing this topic.

acidblue

    Topic Starter


    Rookie

    Perl FTP problem Can't list files
    « on: July 30, 2010, 01:34:11 AM »
    I'm getting a "Bad file descriptor" error when I try and list the files on my FTP server.
    Server is *nix, trying to connect on my WinXP box
    I can connect and login just won't list any files.
    Tried 'ls' as well as 'dir' with same result.

    Code: [Select]
    my $host="FTP.server.net";
    my $directory="/";

    $ftp=Net::FTP->new($host,Debug=> 1,Passive=> 1,Timeout=>240) or $newerr=1;
      push @ERRORS, "Can't ftp to $host: $!\n" if $newerr;
      myerr() if $newerr;
    print "Connected\n";

    $ftp->login("user","pass") or $newerr=1;
    print "Getting file list";
      push @ERRORS, "Can't login to $host: $!\n" if $newerr;
      $ftp->quit if $newerr;
      myerr() if $newerr;
    print "Logged in\n";

    $ftp->cwd($directory) or $newerr=1;
      push @ERRORS, "Can't cd  $!\n" if $newerr;
      myerr() if $newerr;
      $ftp->quit if $newerr;
     

    @files=$ftp->dir or $newerr=1;
      push @ERRORS, "Can't get file list $!\n" if $newerr;
      myerr() if $newerr;
    print "Got  file list\n";   
    foreach(@files) {
      print "$_\n";
      }
    $ftp->quit;


    sub myerr {
      print "Error: \n";
      print @ERRORS;
      exit 0;
    }