net-telnet
net-telnet copied to clipboard
Getting error `waitfor': timed out while waiting for more data (Net::ReadTimeout)
I have simple script to send emails using ruby telnet library here is my code
require 'net/telnet'
localhost = Net::Telnet::new("Host" => "smtp.gmail.com","Timeout" => 10, "Port" => 587, "Waittime" => 20, " FailEOF" => true ) localhost.cmd("mail from: [email protected]"){ |c| print c } localhost.cmd("rcpt to: [email protected]"){ |c| print c } localhost.close
I got this error 'waitfor' timed out while waiting for more data again and again why I am getting this error again and again, what's wrong in the code snipet?
You didn't define neither prompt nor match pattern for your cmd
.
Take a look at the example in README.
I have a similar issue, but neither "Prompt" or "Match" work. This is because the Telnet server don't send any prompt. And the waitfor in the cmd function send only a Prompt in 0.2.0 version. I made a test in rewriting the cmd function that's give me satisfaction. Is my solution correct ? Could a correction be donne in next version ?
def cmd(options) # :yield: recvdata
match = @options["Prompt"]
time_out = @options["Timeout"]
fail_eof = @options["FailEOF"]
typeMatch = "Prompt"
if options.kind_of?(Hash)
cmd = options["Cmd"] if options.has_key?("String")
if options.has_key?("String")
match = options["String"]
typeMatch="String"
end
if options.has_key?("Match")
match = options["Match"]
typeMatch="Match"
end
time_out = options["Timeout"] if options.has_key?("Timeout")
fail_eof = options["FailEOF"] if options.has_key?("FailEOF")
else
cmd = options
end
self.puts(cmd)
if block_given?
waitfor({typeMatch => match, "Timeout" => time_out, "FailEOF" => fail_eof}){|c| yield c }
else
waitfor({typeMatch => match, "Timeout" => time_out, "FailEOF" => fail_eof})
end
end