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