# Net::Telnet

**URL:** <https://www.ruby-forum.com/t/net-telnet/82252>\
**Category:** Ruby\
**Created:** [March 15, 2006, 3:54pm UTC](https://www.ruby-forum.com/t/net-telnet/82252 "2006-03-15T15:54:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shea\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Shea\_M](https://www.ruby-forum.com/u/Shea_M)\
**Post date:** [March 15, 2006, 3:54pm UTC](https://www.ruby-forum.com/t/net-telnet/82252/1 "2006-03-15T15:54:59Z")

</div>

I am having problems with the Telnet module.

Here is my test script:  
`
#!/usr/bin/ruby`

require ‘net/telnet’

tn = Net::Telnet.new( ‘Host’ =\> ‘matilda’,  
‘Telnetmode’=\>true,  
‘Prompt’ =\> ‘$’ ) { |s| puts s }  
tn.login(‘sheam’, ‘my\_pass’) { |s| puts s }  
puts “\>\>\>LOGIN COMPLETE”  
tn.cmd( ‘ls -l’ ) { |s| puts s }  
tc.close

exit 0

If I run this to a solaris telnet server (from a linux box), I get the  
greeting message and a prompt (not my specified prompt, but that is ok).  
But my command is never executed, and a timeout occurs. I do not get  
the ‘\>\>\>LOGIN COMPLETE’ message.

If I run this to a WinXP telnet server (from a XP box), I get this:  
  
Trying fifastbuild1…  
Connected to fifastbuild1.

Welcome to Microsoft Telnet Service

login:  
Testing

password:

Then, a timeout. It appears that my password is not actually being  
sent?  
Ultimately it is the WinXP server that I want to connect to. I was  
just fooling with my solaris and linux box for further testing.

I tried chaning the login line to tn.login(‘user’), followed by a  
tn.puts(‘password’), but it still did not get past the tn.login() line.

Thanks,

~S

---

<div class="post-metadata">

**Author:** ![Shea\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Shea\_M](https://www.ruby-forum.com/u/Shea_M)\
**Post date:** [March 15, 2006, 4:44pm UTC](https://www.ruby-forum.com/t/net-telnet/82252/2 "2006-03-15T16:44:42Z")

</div>

Ok, the following works.

`
#!ruby
require ‘net/telnet’
l_prompt = “Documents and Settings”

tn = Net::Telnet.new( ‘Host’ => ‘matilda’,
‘Telnetmode’=>true,
‘Prompt’ => />$/m ) { |s| puts s }
tn.waitfor(/login:/i) { |s| puts s }
tn.puts(‘Testing’){|s| puts s}
tn.waitfor(/password:/i) { |s| puts s }
tn.puts(‘password’){|s|puts s}
#this line is MS specific
tn.waitfor( /Welcome/i ) { |s| puts s }
tn.cmd( ‘dir’ ){|s| puts s}
tn.close
exit 0
`

So the module was not picking up on the prompts. I thought the Prompt  
variable was to specify what I wanted my prompt to look like, not the  
prompt which the module looks for to determine EOT. Properly setting  
the Prompt value makes the ‘cmd’ function work. But I still have to do  
the login manually. Also, I have to have the correct Prompt value for  
each machine/user/os.

Am I doing something wrong?

Thanks,

~S
