Sha256: bd006bf4b10f1f82e9aa796cc2e2ffde28365f854478790663d288b990c631ab

Contents?: true

Size: 1.35 KB

Versions: 29

Compression:

Stored size: 1.35 KB

Contents

require 'net/ftp/list/parser'
require 'date'

module Net
  class FTP
    module List

      # Parse Microsoft(NT) like FTP LIST entries.
      #
      # == MATCHES
      #
      #   06-25-07  01:08PM       <DIR>          etc
      #   11-27-07  08:45PM                23437 README.TXT
      #
      # == SYNOPSIS
      #
      #   entry = Net::FTP::List::Microsoft.new('06-25-07  01:08PM       <DIR>          etc')
      #   entry.dir?     # => true
      #   entry.basename # => 'etc'
      class Microsoft < Parser

        # Stolen straight from the ASF's commons Java FTP LIST parser library.
        # http://svn.apache.org/repos/asf/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/
        REGEXP = %r!
          ^\s*
          ([0-9\-:\/]{5,})\s+([0-9\-:]{3,}(?:[aApP][mM])?)\s+
          (?:(<DIR>)|([0-9]+))\s+
          (\S.*)
          \s*$
        !x

        # Parse a Microsoft(NT) like FTP LIST entries.
        def initialize(raw)
          super(raw)
          match = REGEXP.match(raw.strip) or raise ParserError
          
          @mtime = DateTime.strptime("#{match[1]} #{match[2]}", "%m-%d-%y  %I:%M%p")

          if match[3] == '<DIR>'
            @dir = true
          else
            @file = true
          end

          # TODO: Permissions, users, groups, date/time.

          @basename = match[5]
        end
      end

    end
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
redcar-dev-0.12.1dev-java plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-dev-0.12.0dev-java plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.11 plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.11.0dev plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.10 plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.9.2 plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.9.1 plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.9.0 plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.8.1 plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.8 plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.7 plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.6.1 plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.6 plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.6.1dev plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.5.1 plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.5 plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.5.6dev plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.5.5dev plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.5.4dev plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb
redcar-0.5.3dev plugins/project/vendor/net-ftp-list/lib/net/ftp/list/microsoft.rb