Hi

I have written a ftp script in perl.It seems to work fine but for some servers it throws an error "Bad file number" while trying to close the connection.What can be the reason for this?How should I resolve it? Following is the ftp section from my code:

if (!$ftp->get($ftp_FileList, $output_file_path."$ftp_FileList"))
                {
                    $logger->error("Status: Can't Get File $ftp_FileList \n");
                    unlink($output_file_path.$ftp_FileList);
                    next;
                }else
                {$logger->info("Update the cache file");
                    print CASHE_WRITE "$ftp_FileList\n";
                    $logger->info("Updated the cache file");
                }
$ftp->quit or die $logger->error("Couldn't quit ftp session\n"),exit;
    $logger->info("---------------------------Quiting FTP----------------------------\n");
    close CASHE_WRITE || $logger->error("Can't close $cacheFile opened in write mode\n");

Thanks
Debangana

Hi

I tried enabling the debug mode and here is what the code logs:

Net::FTP=GLOB(0x40b6b868)<<< 226 Transfer complete.
Net::FTP=GLOB(0x40b6b868)>>> QUIT
Net::FTP=GLOB(0x40b6b868)<<< 221-You have transferred 131595 bytes in 1 files.
Net::FTP: Unexpected EOF on command channel

Please suggest on how to resolve this problem.

Thanks
Debangana

FTP uses two ports (typically 20 and 21). One of those ports is meant to handle all of your commands. The other one, is meant to return data to you. If you receive an EOF on the command channel, it likely means that the command channel (port 21) is indicated that the file transfer has completed successfully, and it's telling you that it's done sending the file (EOF). I've never used the ftp module, so I can't tell you where to fix it... doing it with just sockets, I'd make the code simply discard the EOF, and use it to inform me to close the file handle....you'll want to look at the ftp module's properties, or see if you can error trap the error and discard it.

Sorry for the late reply. Thanks for your suggestion. I will try to investigate more into this.

Regards
Debangana

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.