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

I need to see if anyone has ever had a Bad File Descriptor problem when trying to ftp from a Perl script. If someone could help me with this code I would be greatful, I have tried everything except something that works. I get logged in to the ftp server and see the folder but when I try to put I get that error. Thanks in advanced.
#! c:\perl\bin\perl.exe -w use Net::FTP; # Login info my $host='ernie'; my $user='bert'; my $password='orange'; #print $user; # Change Dir After Login to this dir: my $remote_directory='d:/inetpub/ftproot/carquest'; my $remote_file='pull.txt'; my $home_directory='c:/ftp'; my $file='ftpout.txt'; my $fname="$home_directory/$file"; #print "$fname\n"; $ftp=Net::FTP->new ($host,Timeout=>240); $ftp->login($user, $password) or die "Couldn't login\n"; print "Your are logged in to $host.\n"; $ftp->ascii; #$ftp->get ($remote_file, $home_directory) or die # "Can't get remotefiles: $!\n"; $ftp->put ($fname, $remote_directory) or die "OOPS! Can't send localfiles: $!\n"; print "All files have been transmitted to $host.\n"; $ftp->quit; print "Everything is done.\n";

Replies are listed 'Best First'.
Re: Ftp Script
by nimdokk (Vicar) on Jun 24, 2004 at 18:10 UTC
    At a quick glance, without seeing the actual error messages you are getting, I would hazard a guess that you are attempting to connect to an FTP server on a Windows machine. In your line:

    $ftp->put ($fname, $remote_directory) or die "OOPS! Can't send localfiles: $!\n";

    try the following instead:

    $ftp->cd ($remote_directory) or die "Cannot change to $remote_director +y. $@"; $ftp->put ($fname) or die "OOPS! Can't send localfiles: $@";

    In this code bit, your "cd" will likely fail because when you FTP you will typically be dropped into a login directory and will only be able to access that directory level and lower. I'm going to guess that 'd:\inetpub\ftproot' is the root level so when you log in, you would only see 'carquest.' You have a comment to "Change directories after login," but you never execute the 'cd' command. Also, the arguments for 'put' (and 'get' as well) should be filenames, not directories (from what I recall about Net::FTP and FTP in general).

    Also, note $@ instead of $!. This can give a better description of the error, especially with Net::FTP.