我正在尝试使用 ruby 进行一些基本的脚本编写,以通过 telnet 登录到 Windows 机器,并使用 dos 命令行 ftp 提取一些文件。当我手动执行此操作时,一切都会顺利进行,但是当我通过 ruby 尝试时,我在登录调用中遇到错误。
这是我的完整测试程序:
require 'net/telnet'
tn = Net::Telnet::new("Host"=>"xxx.xxx.xxx.xxx", "Timeout"=>25, "Output_log"=>"output_log.log", "Dump_log"=> "dump_log.log", "Prompt"=>"C:.*>")
tn.login("administrator", "xxxxxxx") {}
tn.cmd('dir')
exit
output_log 的内容不会泄露任何错误:
Trying 208.10.202.187...
Connected to 208.10.202.187.
Welcome to Microsoft Telnet Service
login: administrator
password:
*===============================================================
Welcome to Microsoft Telnet Server.
*===============================================================
C:\Documents and Settings\Administrator>
对于具有非常相似但格式笨拙的内容的 dump_log 也是如此。当我运行程序时,它会停留一段时间,然后输出以下错误:
PS C:\code\tools\deployment> ruby test.rb
C:/Ruby/lib/ruby/1.8/net/telnet.rb:551:in `waitfor': timed out while waiting for more data (Timeout::Error)
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'
from test.rb:3
这让我怀疑 telnet 类没有识别命令提示符。我已经为 Prompt 参数尝试了几种不同的正则表达式字符串,包括默认值,但似乎没有任何帮助。