summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--NEWS4
-rw-r--r--lib/net/ftp.rb17
-rw-r--r--lib/open-uri.rb2
-rw-r--r--test/net/ftp/test_ftp.rb3
5 files changed, 31 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 05825bf..9cead6e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Wed Nov 11 11:58:38 2015 Shugo Maeda <shugo@ruby-lang.org>
+
+ * lib/net/ftp.rb (initialize): Connections are in passive mode per
+ default now. The default mode can be changed by
+ Net::FTP.default_passive=.
+
+ * lib/net/ftp.rb (default_passive=, default_passive): new methods.
+
Wed Nov 11 09:03:12 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* sprintf.c (rb_str_format): respect default value of a hash. no
diff --git a/NEWS b/NEWS
index 075c214..d71b913 100644
--- a/NEWS
+++ b/NEWS
@@ -196,6 +196,10 @@ with all sufficient information, see the ChangeLog file.
* Net::Telnet
* Net::Telnet is extracted to net-telnet gem. It's unmaintain code.
+* Net::FTP
+ * Connections are in passive mode per default now. The default mode can
+ be changed by Net::FTP.default_passive=.
+
* Rake
* Rake is removed from stdlib.
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index 879206c..26bca1a 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -80,12 +80,13 @@ module Net
FTP_PORT = 21
CRLF = "\r\n"
DEFAULT_BLOCKSIZE = BufferedIO::BUFSIZE
+ @@default_passive = true
# :startdoc:
# When +true+, transfers are performed in binary mode. Default: +true+.
attr_reader :binary
- # When +true+, the connection is in passive mode. Default: +false+.
+ # When +true+, the connection is in passive mode. Default: +true+.
attr_accessor :passive
# When +true+, all traffic to and from the server is written
@@ -124,6 +125,18 @@ module Net
# The server's last response.
attr_reader :last_response
+ # When +true+, connections are in passive mode per default.
+ # Default: +true+.
+ def self.default_passive=(value)
+ @@default_passive = value
+ end
+
+ # When +true+, connections are in passive mode per default.
+ # Default: +true+.
+ def self.default_passive
+ @@default_passive
+ end
+
#
# A synonym for <tt>FTP.new</tt>, but with a mandatory host parameter.
#
@@ -151,7 +164,7 @@ module Net
def initialize(host = nil, user = nil, passwd = nil, acct = nil)
super()
@binary = true
- @passive = false
+ @passive = @@default_passive
@debug_mode = false
@resume = false
@sock = NullSocket.new
diff --git a/lib/open-uri.rb b/lib/open-uri.rb
index c63e529..9e4a5e2 100644
--- a/lib/open-uri.rb
+++ b/lib/open-uri.rb
@@ -773,7 +773,7 @@ module URI
# The access sequence is defined by RFC 1738
ftp = Net::FTP.new
ftp.connect(self.hostname, self.port)
- ftp.passive = true if !options[:ftp_active_mode]
+ ftp.passive = !options[:ftp_active_mode]
# todo: extract user/passwd from .netrc.
user = 'anonymous'
passwd = nil
diff --git a/test/net/ftp/test_ftp.rb b/test/net/ftp/test_ftp.rb
index a8d34c6..3af00e7 100644
--- a/test/net/ftp/test_ftp.rb
+++ b/test/net/ftp/test_ftp.rb
@@ -11,9 +11,12 @@ class FTPTest < Test::Unit::TestCase
def setup
@thread = nil
+ @default_passive = Net::FTP.default_passive
+ Net::FTP.default_passive = false
end
def teardown
+ Net::FTP.default_passive = @default_passive
if @thread
@thread.join
end