2

ruby を使用して telnet 経由で Wi​​ndows マシンにログインし、dos コマンド ライン ftp を使用していくつかのファイルをプルする基本的なスクリプトを実行しようとしています。これを手動で行うと、すべてが順調に進みますが、ルビー経由で試すと、ログイン呼び出しでエラーが発生します。

これが私のテストプログラム全体です。

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 パラメーターに対して、デフォルトを含むいくつかの異なる正規表現文字列を試しましたが、何も役に立たないようです。

4

1 に答える 1

3

プロンプトフィールドは文字列ではなく正規表現である必要があると思います

tn = Net::Telnet::new("Host"=>"xxx.xxx.xxx.xxx", "Timeout"=>25,
"Output_log"=>"output_log.log", "Dump_log"=> "dump_log.log",
"Prompt"=> /C:.*>/)
于 2009-06-08T21:18:18.307 に答える