Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Telnet File Handle isn't open on login

by jbev2328 (Novice)
on Sep 24, 2013 at 21:34 UTC ( #1055546=perlquestion: print w/replies, xml ) Need Help??
jbev2328 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks I'm trying to run an inherited pgm which is using Telnet to log into a remote Wireless Network device and then download its startup configuration set. My script is aborting with a strange message "Login failed: filehandle isn't open". I can log into my target device myself and execute the other commands in the script. So my problem appears to be in the remote execution of my script. Any insight would be most appreciated. Thank you JB

Replies are listed 'Best First'.
Re: Telnet File Handle isn't open on login
by VinsWorldcom (Parson) on Sep 24, 2013 at 21:41 UTC

    Any code would be most appreciated. Thank you

      Right. Of course.
      sub GetConfig { my $telnet=new Net::Telnet(); $telnet->output_log; $telnet->timeout($login_timeout); $telnet->errmode('return'); $telnet->prompt('/[\$#>]/'); $telnet->open( $deviceIP ); if( $telnet->errmsg ) { $msg = "Error connecting to device: ".$telnet->errmsg; $telnet->close; return( 252, $msg ); } #first try login without username and just password $telnet->waitfor( Match => '/Password:/'); if( $telnet->errmsg ) { $telnet->login($user, $pass); if( $telnet->errmsg ) { $msg = $telnet->errmsg; $telnet->close; return( 251, $msg ); } } else { $telnet->cmd( $pass ); if( $telnet->errmsg ) { # can't use errmsg as it will give command timed-out # and we should really indicate bad password $msg = "login failed: bad password"; $telnet->close; return( 251, $msg ); } }
      I'm getting a Return Code 251 every time with the message "Login Failed. File Handle isn't open on Login"

        I'm sure you're seeing some problem but I'm pretty sure it isn't what you're telling us.

        First off, the code you posted won't work - it's not complete. See How do I post a question effectively?.

        I've grep'd Net::Telnet for the error message "File Handle isn't open on Login" you're presumably getting from you first "return( 251, $msg );" line as there really is no other place in the code I see that could generate that message. I further grep'd my entire perl/lib, perl/site/lib and perl/vendor/lib directories for that message in some module and I don't find it.

        Please provide (brief) working code that demonstrates the problem.

        In the meantime, show us a screen cut/paste of a console Telnet to the device in question so we can rule out connecting to the device as an issue and prove it's the Perl code.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1055546]
Approved by sparkyichi
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2019-01-18 09:12 GMT
Find Nodes?
    Voting Booth?
    After Perl5, I'm mostly interested in:

    Results (322 votes). Check out past polls.