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

ruby-changes:44806

From: shugo <ko1@a...>
Date: Wed, 23 Nov 2016 09:03:33 +0900 (JST)
Subject: [ruby-changes:44806] shugo:r56879 (trunk): Add a new optinal argument pathname to FTP#stat.

shugo	2016-11-23 09:03:27 +0900 (Wed, 23 Nov 2016)

  New Revision: 56879

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

  Log:
    Add a new optinal argument pathname to FTP#stat.
    
    Based on the patch by soleboxy.
    [Fix GH-1478] [ruby-core:78240] [Feature #12965]

  Modified files:
    trunk/NEWS
    trunk/lib/net/ftp.rb
    trunk/test/net/ftp/test_ftp.rb
Index: NEWS
===================================================================
--- NEWS	(revision 56878)
+++ NEWS	(revision 56879)
@@ -205,6 +205,7 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L205
 
   * Support TLS (RFC 4217).
   * Support hash style options for Net::FTP.new.
+  * Add a new optional argument pathname to Net::FTP#status.
 
 * OpenSSL
 
Index: lib/net/ftp.rb
===================================================================
--- lib/net/ftp.rb	(revision 56878)
+++ lib/net/ftp.rb	(revision 56879)
@@ -1226,11 +1226,13 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L1226
 
     #
     # Returns the status (STAT command).
+    # pathname - when stat is invoked with pathname as a parameter it acts like
+    #            list but alot faster and over the same tcp session.
     #
-    def status
-      line = "STAT" + CRLF
-      print "put: STAT\n" if @debug_mode
-      @sock.send(line, Socket::MSG_OOB)
+    def status(pathname = nil)
+      line = pathname ? "STAT #{pathname}" : "STAT"
+      print "put: #{line}\n" if @debug_mode
+      @sock.send(line + CRLF, Socket::MSG_OOB)
       return getresp
     end
 
Index: test/net/ftp/test_ftp.rb
===================================================================
--- test/net/ftp/test_ftp.rb	(revision 56878)
+++ test/net/ftp/test_ftp.rb	(revision 56879)
@@ -1316,6 +1316,39 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1316
     end
   end
 
+  def test_status_path
+    commands = []
+    server = create_ftp_server { |sock|
+      sock.print("220 (test_ftp).\r\n")
+      commands.push(sock.gets)
+      sock.print("331 Please specify the password.\r\n")
+      commands.push(sock.gets)
+      sock.print("230 Login successful.\r\n")
+      commands.push(sock.gets)
+      sock.print("200 Switching to Binary mode.\r\n")
+      commands.push(sock.gets)
+      sock.print("213 End of status\r\n")
+    }
+    begin
+      begin
+        ftp = Net::FTP.new
+        ftp.read_timeout = 0.2
+        ftp.connect(SERVER_ADDR, server.port)
+        ftp.login
+        assert_match(/\AUSER /, commands.shift)
+        assert_match(/\APASS /, commands.shift)
+        assert_equal("TYPE I\r\n", commands.shift)
+        ftp.status "/"
+        assert_equal("STAT /\r\n", commands.shift)
+        assert_equal(nil, commands.shift)
+      ensure
+        ftp.close if ftp
+      end
+    ensure
+      server.close
+    end
+  end
+
   def test_pathnames
     require 'pathname'
 

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

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