diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/open-uri.rb | 3 | ||||
-rw-r--r-- | test/open-uri/test_open-uri.rb | 39 |
3 files changed, 46 insertions, 1 deletions
@@ -1,3 +1,8 @@ +Sat Sep 12 22:47:24 2009 Tanaka Akira <akr@fsij.org> + + * lib/open-uri.rb (URI::FTP#buffer_open): use the port specified in + the URI. + Sat Sep 12 17:31:42 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> * configure.in (GCC): subst for GCC depending extension libraries. diff --git a/lib/open-uri.rb b/lib/open-uri.rb index 2a6c544fe6..4daec25c01 100644 --- a/lib/open-uri.rb +++ b/lib/open-uri.rb @@ -800,7 +800,8 @@ module URI end # The access sequence is defined by RFC 1738 - ftp = Net::FTP.open(self.host) + ftp = Net::FTP.new + ftp.connect(self.host, self.port) ftp.passive = true if !options[:ftp_active_mode] # todo: extract user/passwd from .netrc. user = 'anonymous' diff --git a/test/open-uri/test_open-uri.rb b/test/open-uri/test_open-uri.rb index 8fb1f06a82..846e87f199 100644 --- a/test/open-uri/test_open-uri.rb +++ b/test/open-uri/test_open-uri.rb @@ -385,5 +385,44 @@ class TestOpenURI < Test::Unit::TestCase } end + def test_ftp + TCPServer.open("127.0.0.1", 0) {|serv| + _, port, _, host = serv.addr + th = Thread.new { + s = serv.accept + begin + s.print "220 Test FTP Server\r\n" + assert_equal("USER anonymous\r\n", s.gets); s.print "331 name ok\r\n" + assert_match(/\APASS .*\r\n/, s.gets); s.print "230 logged in\r\n" + assert_equal("TYPE I\r\n", s.gets); s.print "200 type set to I\r\n" + assert_equal("CWD foo\r\n", s.gets); s.print "250 CWD successful\r\n" + assert_equal("PASV\r\n", s.gets) + TCPServer.open("127.0.0.1", 0) {|data_serv| + _, data_serv_port, _, data_serv_host = data_serv.addr + hi = data_serv_port >> 8 + lo = data_serv_port & 0xff + s.print "227 Entering Passive Mode (127,0,0,1,#{hi},#{lo}).\r\n" + assert_equal("RETR bar\r\n", s.gets); s.print "150 file okay\r\n" + data_sock = data_serv.accept + begin + data_sock << "content" + ensure + data_sock.close + end + s.print "226 transfer complete\r\n" + assert_nil(s.gets) + } + ensure + s.close if s + end + } + begin + content = URI("ftp://#{host}:#{port}/foo/bar").read + assert_equal("content", content) + ensure + Thread.kill(th) + end + } + end end |