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

Dear Perl Experts!, I hope that you help me out with my question. Here is an excerpt of my ftp script that uses net::ftp $ftp->get("Report_$date.csv") or die "Cannot retreive file: $!\n" ,$ftp->message; I get the following output: Cannot retreive file: Bad file descriptor Is there a way to see what the input is on the cmd line? Thanks all - this is driving me crazy but I can do this manually but it just doesn't work via the perl script. Regards

Replies are listed 'Best First'.
Re: Net::Ftp Issue
by apl (Monsignor) on Feb 04, 2008 at 17:27 UTC
    I humbly suggest you modify your code to:
    my $path = "Report_".$date.".csv"; net::ftp $ftp->get($path) or die "Cannot get '$path': $!\n";
    That would answer your immediate question. You might want to do a pwd (or a cd) first; you're probably not in the directory you think you are.
      thanks apl! But no draw. The output gives me RETR and then the filename, which is correct, But still gives me the error "Bad file descriptor" I even copied and pasted that output and manually retreived the file and it was fine! I even made sure the path was correct ($ftp->pwd()). I suspect that the module may be inputting something else on the cmd line but how can I display that? Perhaps $ftp->message displays this (but not sure how to display it if it does) Can you provide some insight. Regards - perl newbie! :)
        Have you tried repeating the sequence of ftp commands interactively? (You can always ls to confirm the existence of the file.)

        Perhaps you could do a ftp->dir();, to see if the file shows up in the directory listing?

        For that matter, you could manually do a ls -b on the directory in question. Perhaps there's a non-printable character in the name of the file you're interested in.

Re: Net::Ftp Issue
by kirillm (Friar) on Feb 04, 2008 at 22:54 UTC

    Hi there,

    You say that this code

    $ftp->get("Report_$date.csv") or die "Cannot retreive file: $!\n", $ft +p->message;

    gives this error message:

    Cannot retreive file: Bad file descriptor

    As you see, $ftp->message is actually empty, which may indicate that the issue is not with the FTP server, but with something locally. Please post how you create the $ftp object and what FTP commands you issue prior to issuing the get FTP command.

    To see what commands Net::FTP sends to the ftp server, you can pass Debug => 1 to Net::FTP->new(). Also consier calling $ftp->get() with 2 arguments, specifying full path to where the file should be stored locally as the second argument. There might be some issues with permissions.

    Good luck.

Re: Net::Ftp Issue
by marcussen (Pilgrim) on Feb 04, 2008 at 23:22 UTC
    Do not forget that the Net::Ftp contructor has a debug option that will allow you to capture all commands via STDERR and attempt to recreate the problem manually.