Class: Net::FTP::List::Microsoft

Inherits:
Parser
  • Object
show all
Defined in:
lib/net/ftp/list/microsoft.rb

Overview

Parse Microsoft(NT) like FTP LIST entries.

MATCHES

06-25-07  01:08PM       <DIR>          etc
11-27-07  08:45PM                23437 README.TXT

Constant Summary

REGEXP =

Stolen straight from the ASF's commons Java FTP LIST parser library. svn.apache.org/repos/asf/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/

%r!
  ^\s*
  ([0-9\-:\/]{5,})\s+([0-9\-:]{3,}(?:[aApP][mM])?)\s+
  (?:(<DIR>)|([0-9]+))\s+
  (\S.*)
  \s*$
!x

Class Method Summary (collapse)

Class Method Details

+ (Object) parse(raw)

Parse a Microsoft(NT) like FTP LIST entries.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/net/ftp/list/microsoft.rb', line 22

def self.parse(raw)
  match = REGEXP.match(raw.strip) or return false

  mtime = DateTime.strptime("#{match[1]} #{match[2]}", "%m-%d-%y  %H:%M%p")
  is_dir = match[3] == '<DIR>'
  filesize = is_dir ? 0 : match[4].to_i

  emit_entry(
    raw,
    :dir => is_dir,
    :file => !is_dir,
    :filesize => filesize,
    :basename => match[5],
    :mtime => mtime
  )
end