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

Hi, I've got a script that logs into an FTP server and I want it to download a file. It logs in ok checks the file is there but when it does the 'get' it dies with the following message " Bad file number". Heres some of the code;
use Net::FTP; $address ="gamefiles.blueyonder.co.uk"; $hl_path = "/blueyondergames/halflife/patches/win32/"; $ftp = Net::FTP->new($address) or die "Can't connect:$@\n"; $ftp->login() or die "Couldn't login\n"; $ftp->cwd($hl_path) or die "Couldn't change directory to $hl-path: $!\ +n"; @lines_hl = $ftp->dir(".") or die "Can't get a list of files\n"; # lets check if the files are there. &checkFileExists("HL", @lines_hl); sub checkFileExists { print "pt = @_[0]\n"; if (@_[0] == "HL") { $patch = "11081109.exe"; } elsif (@_[0] == "CS") { $patch = "cs1415.exe"; #check this filename } print "patch = $patch\n"; foreach $file (@_) { if ($file =~ "$patch") { print "hit!\n"; &downloadfile($patch); break; } } } sub downloadfile { my $file = "@_[0]"; chomp($file); print "Downloading $file!\n"; $ftp->binary() or die "Can't change to Binary: $!\n"; #change i +t to a binary transfer. $ftp->get($file) or die "error downloading: $!\n"; $ftp->quit(); }
Any ideas why? Thanks Chris

Replies are listed 'Best First'.
Re: Bad file number
by Abigail-II (Bishop) on Jun 12, 2002 at 15:49 UTC
    Have you tried downloading the file with a standard FTP client? Does that work? Make sure the FTP client is in active mode, as that's the default with Net::FTP as well. If it fails interactively with active mode, but succeeds with passive mode, you need to give the Passive option to the Net::FTP constructor.

    See also the Net::FTP manual page.

    Abigail

      I encountered the same error. My script brought a list of files from a unix server through the firewall then PUT the file(s) on an NT server. It failed on the PUT during the inbound session. Process of elimination found the problem to be permissions set on the NT server when I was not allowed to delete existing data files. It would'nt allow duplicate data file names to be written either. For testing I had the script put the file with an added extension and it worked.