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

Is there anything special I need to do when having a form (POST method) upload I file using Net::FTP? This is sort of what I have:
#!/usr/bin/perl use CGI qw(:all); use Net::FTP; $ftp = Net::FTP->new('foo.com') or die "PROBLEM: $!\n"; $ftp->login('foo','bar') or die "PROBLEM: $!\n"; $ftp->cwd('/incoming') or die "PROBLEM: $!\n"; $ftp->put(param('file')) or die "PROBLEM: $!\n"; $ftp->quit();
That's basically it. I get a "PROBLEM: Bad file descriptor" error in my log. Please reply if you can help

-NM

Replies are listed 'Best First'.
RE: Net::FTP and param()
by t0mas (Priest) on Aug 15, 2000 at 10:14 UTC
      I just found out you should use the new upload() function. This still didn't fix the problem, however and I tried your solution, too.
        Try with at temporary file:
        my $C = new CGI; my $filehandle = $C->upload('file'); open OUTFILE, ">/tmp/tmpfile" or die "Can't create: $!"; while (<$filehandle>) {print OUTFILE;} close OUTFILE or die "Can't close: $!";
        and then the ftp stuff with $ftp->put('/tmp/tmpfile').
        This will of cause not be good enough in a multi-user environment, where you'll need to handle simultaneous uploads. You will have to create a unique temporary name, perhaps with File::MkTemp.

        /brother t0mas
RE: Net::FTP and param()
by merlyn (Sage) on Aug 15, 2000 at 15:21 UTC
    I would seriously hope that you have some verification that the filename makes sense. Remember that some browsers send just the basename of the file, while others send the full path. It'd be better if you had a separate field for "name you want on the server", rather than relying at all on the "hint" provided by the browser about the original name.

    And use taint mode! That would probably have caught you with your pants down on this one! Don't use untested user data to decide filenames or other external things!

    -- Randal L. Schwartz, Perl hacker

Re: Net::FTP and param()
by NeverMore (Acolyte) on Aug 16, 2000 at 03:46 UTC
    I just discovered the problem was located on a different line:
    $ftp->ls() or die "PROBLEM: $!";

    -NM