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

I am writing a program, to telnet to a server and perfrom certain tasks (tasks -> unimportant). When I try to telnet to a server remotely, I can access the server with a certain login name/password, but when i enter another valid login name/password, it times out. Do you know why it worked for a screen name but yet it didn't work for another one. Is there something wrong with the code?? Here is some of the code. Thank you.
#!/usr/bin/perl # file: telnet_a.pl use Net::Telnet; use Term::ReadKey; #connects to the server of your choice $telnet = Net::Telnet->new('osf1.gmu.edu'); #asks for login name with password print "Login Name : "; $HOST = <STDIN> or die print "not a valid name"; #reads in the password without showing the character #being typed in ReadMode("noecho",STDIN); print "Password : "; $USER = <>; print "\n"; #restor to normal settings ReadMode("original",STDIN); #connects to server $telnet->login($HOST,$USER) or die print "can't access server"; $telnet->cmd('ls');

Replies are listed 'Best First'.
Re: login remotely through telnet
by Elijah (Hermit) on Apr 01, 2004 at 17:43 UTC
    Well the following worked fine for me:
    #!/usr/bin/perl use Net::Telnet; $telnet = Net::Telnet->new('192.168.1.65'); print "Login Name : "; $HOST = <STDIN>; print "Password : "; $USER = <>; $telnet->login($HOST,$USER) or die print "can't access server"; @ls = $telnet->cmd('ls'); for(@ls){print;}
    I do not have the Term::ReadKey module installed on my system so I removed that. There could be your problem. Or at least I had no problem not using this module and that was the only difference between your code and mine. It would also be a good idea to chomp your variables before using them incase a user enters a whitespace at the end of their user or pass or if a newline sneaks through somehow.

    Edit:

    Ok I installed that module to try and give you some better advice but alas mine runs perfectly.

    #!/usr/bin/perl use Net::Telnet; use Term::ReadKey; $telnet = Net::Telnet->new('192.168.1.65'); print "Login Name : "; $HOST = <STDIN>; ReadMode("noecho",STDIN); print "Password : "; $USER = <>; print "\n"; ReadMode("original",STDIN); $telnet->login($HOST,$USER) or die print "can't access server"; @ls = $telnet->cmd('ls'); for(@ls){print;}
    Could it be an issue with the telnet server? Does the second user you are trying actually exist on the system?
Re: login remotely through telnet
by iburrell (Chaplain) on Apr 01, 2004 at 22:36 UTC
    What does it say when you turn on debugging? Deadlock with telnet is common when unexpected responses come from the server.

    For example, the login() docs say: "If any of those prompts sent by the remote side don't match what's expected, this method will time-out, unless timeout is turned off."