Here are some lightly-tested patches.

(1) A patch to Net::Telnet which adds a new option "FailEOF". If you specify

    sock = Net::Telnet.new(...., "FailEOF" => true)
or
    sock.waitfor("Match" => /foo/, "FailEOF" => true)

then if the remote side closes the connection before the expected response is
seen, an EOFError will be raised. If this option is not set then the old
behaviour is maintained.

(2) A patch to IO#expect which raises EOFError instead of NoMethodError if
the remote side closes the connection before the expected response is seen.

Regards,

Brian.
--- /usr/lib/ruby/1.8/net/telnet.rb	2005-09-14 16:21:31.000000000 +0100
+++ telnet.rb	2007-05-31 14:43:21.000000000 +0100
@@ -520,10 +520,15 @@
     #            value specified when this instance was created will be
     #            used, or, failing that, the default value of 0 seconds,
     #            which means not to wait for more input.
+    # FailEOF:: if true, when the remote end closes the connection then an
+    #           EOFError will be raised. Otherwise, defaults to the old
+    #           behaviour that the function will return whatever data
+    #           has been received already, or nil if nothing was received.
     #           
     def waitfor(options) # :yield: recvdata
       time_out = @options["Timeout"]
       waittime = @options["Waittime"]
+      fail_eof = @options["FailEOF"]
 
       if options.kind_of?(Hash)
         prompt   = if options.has_key?("Match")
@@ -535,6 +540,7 @@
                    end
         time_out = options["Timeout"]  if options.has_key?("Timeout")
         waittime = options["Waittime"] if options.has_key?("Waittime")
+        fail_eof = options["FailEOF"]  if options.has_key?("FailEOF")
       else
         prompt = options
       end
@@ -579,6 +585,7 @@
           line += buf
           yield buf if block_given?
         rescue EOFError # End of file reached
+          raise if fail_eof
           if line == ''
             line = nil
             yield nil if block_given?
--- /usr/lib/ruby/1.8/expect.rb	2006-11-22 14:06:58.000000000 +0000
+++ lib/rds/expect.rb	2007-05-31 14:40:22.000000000 +0100
@@ -14,7 +14,7 @@
         result = nil
         break
       end
-      c = getc.chr
+      c = (getc || (raise EOFError)).chr
       buf << c
       if $expect_verbose
         STDOUT.print c