views:

802

answers:

2

I am extremely new to ruby and just trying to use it to do some basic scripting. Namely telnet into a machine and use the dos ftp client to pull some files over.

The problem that I have is when I try to telnet into the machine manually (from command prompt) I get the following message:

Welcome to Microsoft Telnet Client

Escape Character is 'CTRL+]'

You are about to send your password information to a remote computer in Internet zone. This might not be safe. Do you want to send anyway(y/n):

When I use ruby's telnet class (net/telnet) login() it hangs on the password prompt. This leads me to think that it is not taking the message into account, sending the username to the message and the password to the username prompt. How do I handle this situation?

Edit: The login process does seem to be hanging during the password prompt. It is merely my suspicion that this is caused by the above message, any other ideas are appreciated. I tried to echo everything and I get the following:

irb(main):030:0> tn = Net::Telnet::new("Host"=>"xxx.xxx.xxx.xxx", "Timeout"=>10) => #<TCPSocket:0x2d8aafc>
irb(main):031:0> tn.login("administrator", "password") {|c| print c}
Welcome to Microsoft Telnet Service

login: administrator
password: Timeout::Error: timed out while waiting for more data
        from C:/Ruby/lib/ruby/1.8/net/telnet.rb:551:in `waitfor'
        from C:/Ruby/lib/ruby/1.8/net/telnet.rb:685:in `cmd'
        from C:/Ruby/lib/ruby/1.8/net/telnet.rb:730:in `login'
+2  A: 

First off, try passing the Output_log parameter so that you can see everything that is going on:

host = Net::Telnet::new(
       "Host"       => "localhost",
       "Port"       => 23,
       "Output_log" => "output_log")

See if this tells you what is going on, the only other option I see that might make a difference is Binmode => false.

Check the docs for more info :-)

Edit 1: You might also check the Prompt option. Apparently it's what decides when the command has finished. If it doesn't match your prompt on your server, it will almost certainly mess it up.

Topher Fangio
+2  A: 

I figured it out. Not going to delete this on the off chance that someone else runs into the issue but my timeout was set too low. Setting it to 25 solved the problem.

George Mauer
You should select this as your answer so that others searching will see that a solution has been reached :-)
Topher Fangio
If you're timing out prematurely after 10 seconds, you may just want to set the timeout to nil and let the connect() call handle the timeouts.
Bob Aman