[前][次][番号順一覧][スレッド一覧]

ruby-changes:40451

From: shugo <ko1@a...>
Date: Wed, 11 Nov 2015 12:49:05 +0900 (JST)
Subject: [ruby-changes:40451] shugo:r52532 (trunk): * lib/net/ftp.rb (initialize): Connections are in passive mode per

shugo	2015-11-11 12:48:45 +0900 (Wed, 11 Nov 2015)

  New Revision: 52532

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52532

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/lib/net/ftp.rb
    trunk/lib/open-uri.rb
    trunk/test/net/ftp/test_ftp.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52531)
+++ ChangeLog	(revision 52532)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Nov 11 11:58:38 2015  Shugo Maeda  <shugo@r...>
+
+	* 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@r...>
 
 	* sprintf.c (rb_str_format): respect default value of a hash.  no
Index: lib/open-uri.rb
===================================================================
--- lib/open-uri.rb	(revision 52531)
+++ lib/open-uri.rb	(revision 52532)
@@ -773,7 +773,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/open-uri.rb#L773
       # 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
Index: lib/net/ftp.rb
===================================================================
--- lib/net/ftp.rb	(revision 52531)
+++ lib/net/ftp.rb	(revision 52532)
@@ -80,12 +80,13 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L80
     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 https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L125
     # 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 https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L164
     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
Index: NEWS
===================================================================
--- NEWS	(revision 52531)
+++ NEWS	(revision 52532)
@@ -196,6 +196,10 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L196
 * 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.
 
Index: test/net/ftp/test_ftp.rb
===================================================================
--- test/net/ftp/test_ftp.rb	(revision 52531)
+++ test/net/ftp/test_ftp.rb	(revision 52532)
@@ -11,9 +11,12 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L11
 
   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]