зеркало из https://github.com/github/ruby.git
* lib/open-uri.rb (URI::FTP#buffer_open): use the port specified in
the URI. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
c35f659524
Коммит
188e9667dc
|
@ -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.
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче