From 707a0a946d55df772012b282c594df790371ec23 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 27 Aug 1998 03:55:54 +0000 Subject: 1.1c3 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/telnet.rb | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'lib/telnet.rb') diff --git a/lib/telnet.rb b/lib/telnet.rb index 4e690b9aa8..ca68e1b3e5 100644 --- a/lib/telnet.rb +++ b/lib/telnet.rb @@ -1,8 +1,11 @@ # # telnet.rb -# ver0.122 1998/08/05 +# ver0.13 1998/08/25 # Wakou Aoyama # +# ver0.13 1998/08/25 +# add print method. +# # ver0.122 1998/08/05 # support for HP-UX 10.20 thanks to WATANABE Tetsuya # socket.<< --> socket.write @@ -59,6 +62,9 @@ # "Prompt" => /[$%#>] $//, # "Timeout" => 10}){|c| print c } # +# == send string +# host.print("string") +# # == login # host.login("username", "password") # host.login({"Name" => "username", @@ -82,6 +88,17 @@ # localhost.login("username", "password"){|c| print c } # localhost.cmd("command"){|c| print c } # localhost.close +# +# == sample 2 +# checks a POP server to see if you have mail. +# +# pop = Telnet.new({"Host" => "your_destination_host_here", +# "Port" => 110, +# "Telnetmode" => FALSE, +# "Prompt" => /^\+OK/}) +# pop.cmd("user " + "your_username_here"){|c| print c} +# pop.cmd("pass " + "your_password_here"){|c| print c} +# pop.cmd("list"){|c| print c} require "socket" require "delegate" @@ -191,7 +208,7 @@ class Telnet < SimpleDelegator # respond to "IAC AYT" (are you there) str.gsub!(/([^#{IAC}])?#{IAC}#{AYT}/no){ - @sock.write("nobody here but us pigeons" + CR) + @sock.write("nobody here but us pigeons" + EOL) $1 } @@ -234,6 +251,10 @@ class Telnet < SimpleDelegator line end + def print(string) + @sock.write(string.gsub(/\n/, EOL) + EOL) + end + def cmd(options) match = @options["Prompt"] timeout = @options["Timeout"] @@ -247,7 +268,7 @@ class Telnet < SimpleDelegator end select(nil, [@sock]) - @sock.write(string.gsub(/\n/, CR) + CR) + @sock.write(string.gsub(/\n/, EOL) + EOL) if iterator? waitfor({"Prompt" => match, "Timeout" => timeout}){|c| yield c } else -- cgit v1.2.3