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

Here's my problem:
use CGI qw(:all); use Net::FTP; $file2 = upload('T3') or stufferror(); # Upload() returns a filehandle +. stufferror() isn't executed at all. # some more stuff goes here (FTP connection established) $ftp->put_unique($file2,'stuff.txt') or uploaderror(); # this error is + executed. It says 'Bad File descriptor'. # rest of stuff
Any ideas? -NM

Replies are listed 'Best First'.
Re: NeverMore
by lhoward (Vicar) on Jun 03, 2000 at 01:26 UTC
    I did some quick testing and can get a test wrapper based on your code sample (CGI upload straight to an FTP put) and it worked just fine. Have you tried removing the FTP code for now and just printing the contents of the file back to the webpage?
    while(<$file2>){ print }
    That would at least narrow down the problem by half telling you if the problem is in the FTP or in the filehandle coming out of the upload. (be sure to upload a TEXT file when you test this or it could look real ugly).

    And you've probably already gotten this, but make sure that your form is configured as follows to allow for file uploads:

    <form method="post" enctype="multipart/form-data">
    Also you should double-check that your stufferror function was not reached. Catching errors messages from CGI's can be tricky.
Re: NeverMore
by chromatic (Archbishop) on Jun 07, 2000 at 01:59 UTC
    What does upload() return if it fails? You might have to do a dual-part check, if it doesn't return undef or something common like that:
    $file2 = upload('T3'); stufferror() unless (defined $file2); # for debugging purposes # print "->$file2<-\n";
    BigJoe's idea won't work, I can see that right away. I think he's thinking of something more like: $ftp->upload('T3'); which isn't what you want to do, as you have code elsewhere that does this.
Re: NeverMore
by BigJoe (Curate) on Jun 03, 2000 at 01:18 UTC
    This is just an Idea have you tried
    $file2 -> upload('T3') or stufferror(); ?


    This has not been tested though.

    BigJoe