Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Net::FTP bad file descriptor

Status
Not open for further replies.

surfwaloha

Technical User
Sep 11, 2003
1
US
I could have sworn I had Net::FTP working just fine, but now I constantly get a "Bad file descriptor" error from the following simple code.
NOTE that I am able to get the file "sm.state" with no problem from mannually from the command line

thanks in advance for any help
--- newbie

#!/usr/bin/perl -w
# written by CB on Sept. 4, 2003 to parse bls NAICS data
#
use Net::FTP;

$ftp = Net::FTP->new("ftp.bls.gov", Timeout => 60, Debug =>3) or die "Cannot contact blshost: $!";

$ftp->login('anonymous','guest') or die "Can't login blshost:" , $ftp->message;

# Change the working directory

$ftp->cwd("/pub/time.series/sm/") or die "Can't change directory blshost:" , $ftp->message;
# Get the file from the ftp server

$ftp->get("sm.state") or warn "Couldn't get sm.state, skipped: $!";
# Close the connection to the FTP server.

$ftp->quit or die "Couldn't close the connection cleanly: $!";
# We're done!

Here is the debug output

Net::FTP>>> Net::FTP(2.71)
Net::FTP>>> Exporter(5.562)
Net::FTP>>> Net::Cmd(2.24)
Net::FTP>>> IO::Socket::INET(1.25)
Net::FTP>>> IO::Socket(1.26)
Net::FTP>>> IO::Handle(1.21)
Net::FTP=GLOB(0x106c4)<<< 220 blsweb2 Microsoft FTP Service (Version 4.0).
Net::FTP=GLOB(0x106c4)>>> user anonymous
Net::FTP=GLOB(0x106c4)<<< 331 Anonymous access allowed, send identity (e-mail name) as password.
Net::FTP=GLOB(0x106c4)>>> PASS ....
Net::FTP=GLOB(0x106c4)<<< 230 Anonymous user logged in.
Net::FTP=GLOB(0x106c4)>>> CWD /pub/time.series/sm
Net::FTP=GLOB(0x106c4)<<< 250 CWD command successful.
Net::FTP=GLOB(0x106c4)>>> PORT 192,168,123,106,194,85
Net::FTP=GLOB(0x106c4)<<< 200 PORT command successful.
Net::FTP=GLOB(0x106c4)>>> RETR sm.state
Net::FTP=GLOB(0x106c4)<<< 150 Opening ASCII mode data connection for sm.state(756 bytes).
Couldn't get sm.state, skipped: Bad file descriptor at parse_bls_sm_test.pl line 20.
[localhost:~/documents/perl] carlstan% perl parse_bls_sm_test.pl
Net::FTP>>> Net::FTP(2.71)
Net::FTP>>> Exporter(5.562)
Net::FTP>>> Net::Cmd(2.24)
Net::FTP>>> IO::Socket::INET(1.25)
Net::FTP>>> IO::Socket(1.26)
Net::FTP>>> IO::Handle(1.21)
Net::FTP=GLOB(0xff90)<<< 220 blsweb2 Microsoft FTP Service (Version 4.0).
Net::FTP=GLOB(0xff90)>>> user anonymous
Net::FTP=GLOB(0xff90)<<< 331 Anonymous access allowed, send identity (e-mail name) as password.
Net::FTP=GLOB(0xff90)>>> PASS ....
Net::FTP=GLOB(0xff90)<<< 230 Anonymous user logged in.
Net::FTP=GLOB(0xff90)>>> CWD /pub/time.series/sm/
Net::FTP=GLOB(0xff90)<<< 250 CWD command successful.
Net::FTP=GLOB(0xff90)>>> PORT 192,168,123,106,194,119
Net::FTP=GLOB(0xff90)<<< 200 PORT command successful.
Net::FTP=GLOB(0xff90)>>> RETR sm.state
Net::FTP=GLOB(0xff90)<<< 150 Opening ASCII mode data connection for sm.state(756 bytes).
Couldn't get sm.state, skipped: Bad file descriptor at parse_bls_sm_test.pl line 17.
Net::FTP=GLOB(0xff90)>>> QUIT
Net::FTP=GLOB(0xff90)<<< 425 Can't open data connection.






 
It could be a problem with passive ftp. If it works on a cmd line ftp try running the status command in the ftp client. Some are set with passive on by default. If passive is on add:
Code:
Passive => 1
to your Net::FTP constructor. Not sure if it's the problem but can't hurt to look at.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top