net-ftp-list 2.0.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ .idea/*
7
+ .idea/**/*
data/README.txt CHANGED
@@ -30,13 +30,15 @@ See the RFC for more guff on LIST and NLST: http://www.ietf.org/rfc/rfc0959.txt
30
30
  ftp = Net::FTP.open('somehost.com', 'user', 'pass')
31
31
  ftp.list('/some/path') do |e|
32
32
  entry = Net::FTP::List.parse(e)
33
-
33
+
34
34
  # Ignore everything that's not a file (so symlinks, directories and devices etc.)
35
35
  next unless entry.file?
36
36
 
37
37
  # If entry isn't a kind_of Net::FTP::List::Unknown then there is a bug in Net::FTP::List if this isn't the
38
38
  # same name as ftp.nlist('/some/path') would have returned.
39
- puts entry.basename
39
+ # Format the entry showing its file size and modification time
40
+ puts "#{entry.basename}, #{entry.filesize}, #{entry.mtime}"
41
+
40
42
  end
41
43
 
42
44
  == CREDITS
data/VERSION.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  ---
2
- :minor: 0
3
- :patch: 0
4
2
  :major: 2
3
+ :minor: 1
4
+ :patch: 1
5
+ :build:
@@ -1,4 +1,5 @@
1
1
  require 'net/ftp/list/parser'
2
+ require 'date'
2
3
 
3
4
  module Net
4
5
  class FTP
@@ -33,9 +34,12 @@ module Net
33
34
  super(raw)
34
35
  match = REGEXP.match(raw.strip) or raise ParserError
35
36
 
37
+ @mtime = DateTime.strptime("#{match[1]} #{match[2]}", "%m-%d-%y %I:%M%p")
38
+
36
39
  if match[3] == '<DIR>'
37
40
  @dir = true
38
41
  else
42
+ @filesize = match[4].to_i
39
43
  @file = true
40
44
  end
41
45
 
@@ -1,4 +1,5 @@
1
1
  require 'net/ftp/list/parser'
2
+ require 'time'
2
3
 
3
4
  module Net
4
5
  class FTP
@@ -33,6 +34,9 @@ module Net
33
34
  super(raw)
34
35
  match = REGEXP.match(raw.strip) or raise ParserError
35
36
 
37
+ @mtime = Time.parse(match[5])
38
+ @filesize = match[4].to_i
39
+
36
40
  if match[1] == 'd'
37
41
  @dir = true
38
42
  else
@@ -43,17 +43,25 @@ module Net
43
43
 
44
44
  # Looks like a directory, try CWD.
45
45
  def dir?
46
- !!@dir ||= false
46
+ !!(@dir ||= false)
47
47
  end
48
48
 
49
49
  # Looks like a file, try RETR.
50
50
  def file?
51
- !!@file ||= false
51
+ !!(@file ||= false)
52
52
  end
53
53
 
54
54
  # Looks like a symbolic link.
55
55
  def symlink?
56
- !!@symlink ||= false
56
+ !!(@symlink ||= false)
57
+ end
58
+
59
+ def mtime
60
+ @mtime
61
+ end
62
+
63
+ def filesize
64
+ @filesize
57
65
  end
58
66
 
59
67
  class << self
@@ -1,3 +1,4 @@
1
+ require 'time'
1
2
  require 'net/ftp/list/parser'
2
3
 
3
4
  module Net
@@ -7,7 +8,7 @@ module Net
7
8
  # Parse Unix like FTP LIST entries.
8
9
  #
9
10
  # == MATCHES
10
- #
11
+ #
11
12
  # drwxr-xr-x 4 steve group 4096 Dec 10 20:23 etc
12
13
  # -rw-r--r-- 1 root other 531 Jan 29 03:26 README.txt
13
14
  #
@@ -46,6 +47,8 @@ module Net
46
47
  end
47
48
 
48
49
  # TODO: Permissions, users, groups, date/time.
50
+ @filesize = match[18].to_i
51
+ @mtime = Time.parse("#{match[19]} #{match[20]}")
49
52
 
50
53
  @basename = match[21].strip
51
54
 
@@ -0,0 +1,53 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{net-ftp-list}
8
+ s.version = "2.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Stateless Systems"]
12
+ s.date = %q{2010-07-30}
13
+ s.email = %q{enquiries@statelesssystems.com}
14
+ s.extra_rdoc_files = [
15
+ "README.txt"
16
+ ]
17
+ s.files = [
18
+ ".gitignore",
19
+ "README.txt",
20
+ "Rakefile",
21
+ "VERSION.yml",
22
+ "lib/net/ftp/list.rb",
23
+ "lib/net/ftp/list/microsoft.rb",
24
+ "lib/net/ftp/list/netware.rb",
25
+ "lib/net/ftp/list/parser.rb",
26
+ "lib/net/ftp/list/unix.rb",
27
+ "net-ftp-list.gemspec",
28
+ "test/test_net_ftp_list_microsoft.rb",
29
+ "test/test_net_ftp_list_netware.rb",
30
+ "test/test_net_ftp_list_unix.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/stateless-systems/net-ftp-list}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.5}
36
+ s.summary = %q{Parse FTP LIST command output.}
37
+ s.test_files = [
38
+ "test/test_net_ftp_list_microsoft.rb",
39
+ "test/test_net_ftp_list_unix.rb",
40
+ "test/test_net_ftp_list_netware.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
+ else
49
+ end
50
+ else
51
+ end
52
+ end
53
+
@@ -18,6 +18,11 @@ class TestNetFTPListMicrosoft < Test::Unit::TestCase
18
18
  assert_instance_of Net::FTP::List::Unknown, Net::FTP::List.parse("++ bah! ++")
19
19
  end
20
20
 
21
+ def test_ruby_microsoft_mtime
22
+ assert_equal DateTime.strptime('06-25-07 01:08PM', "%m-%d-%y %I:%M%p"), @dir.mtime
23
+ assert_equal DateTime.strptime('11-27-07 08:45PM', "%m-%d-%y %I:%M%p"), @file.mtime
24
+ end
25
+
21
26
  def test_ruby_microsoft_like_dir
22
27
  assert_equal 'etc', @dir.basename
23
28
  assert @dir.dir?
@@ -30,4 +35,8 @@ class TestNetFTPListMicrosoft < Test::Unit::TestCase
30
35
  assert !@file.dir?
31
36
  end
32
37
 
38
+ def test_filesize
39
+ assert @dir.filesize.nil?
40
+ assert_equal 23437, @file.filesize
41
+ end
33
42
  end
@@ -17,6 +17,11 @@ class TestNetFTPListNetware < Test::Unit::TestCase
17
17
  assert_instance_of Net::FTP::List::Unknown, Net::FTP::List.parse("++ bah! ++")
18
18
  end
19
19
 
20
+ def test_ruby_netware_mtime
21
+ assert_equal @dir.mtime, Time.parse('Jun 27 23:46')
22
+ assert_equal @file.mtime, Time.parse('Jun 22 06:22')
23
+ end
24
+
20
25
  def test_ruby_netware_like_dir
21
26
  assert_equal 'public.www', @dir.basename
22
27
  assert @dir.dir?
@@ -29,4 +34,9 @@ class TestNetFTPListNetware < Test::Unit::TestCase
29
34
  assert !@file.dir?
30
35
  end
31
36
 
37
+ def test_filesize
38
+ assert_equal 512, @dir.filesize
39
+ assert_equal 2767, @file.filesize
40
+ end
41
+
32
42
  end
@@ -4,11 +4,12 @@ require 'net/ftp/list'
4
4
  class TestNetFTPListUnix < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
- @dir = Net::FTP::List.parse 'drwxr-xr-x 4 user group 4096 Dec 10 20:23 etc'
8
- @file = Net::FTP::List.parse '-rw-r--r-- 1 root other 531 Jan 29 03:26 README'
9
- @other_dir = Net::FTP::List.parse 'drwxr-xr-x 8 1791 600 4096 Mar 11 07:57 forums'
10
- @spaces = Net::FTP::List.parse 'drwxrwxr-x 2 danial danial 72 May 23 12:52 spaces suck'
11
- @symlink = Net::FTP::List.parse 'lrwxrwxrwx 1 danial danial 4 Apr 30 15:26 bar -> /etc'
7
+ @dir = Net::FTP::List.parse 'drwxr-xr-x 4 user group 4096 Dec 10 20:23 etc'
8
+ @file = Net::FTP::List.parse '-rw-r--r-- 1 root other 531 Jan 29 03:26 README'
9
+ @other_dir = Net::FTP::List.parse 'drwxr-xr-x 8 1791 600 4096 Mar 11 07:57 forums'
10
+ @spaces = Net::FTP::List.parse 'drwxrwxr-x 2 danial danial 72 May 23 12:52 spaces suck'
11
+ @symlink = Net::FTP::List.parse 'lrwxrwxrwx 1 danial danial 4 Apr 30 15:26 bar -> /etc'
12
+ @older_date = Net::FTP::List.parse '-rwxrwxrwx 1 owner group 154112 Feb 15 2008 participando.xls'
12
13
  end
13
14
 
14
15
  def test_parse_new
@@ -23,6 +24,12 @@ class TestNetFTPListUnix < Test::Unit::TestCase
23
24
  assert_instance_of Net::FTP::List::Unknown, Net::FTP::List.parse("++ bah! ++")
24
25
  end
25
26
 
27
+ def test_ruby_unix_like_date
28
+ assert_equal Time.parse("Mar 11 07:57"), @other_dir.mtime
29
+ assert_equal Time.parse("Apr 30 15:26"), @symlink.mtime
30
+ assert_equal Time.parse("Feb 15 2008"), @older_date.mtime
31
+ end
32
+
26
33
  def test_ruby_unix_like_dir
27
34
  assert_equal 'etc', @dir.basename
28
35
  assert @dir.dir?
@@ -52,4 +59,12 @@ class TestNetFTPListUnix < Test::Unit::TestCase
52
59
  assert !@file.dir?
53
60
  end
54
61
 
62
+ def test_filesize
63
+ assert_equal 4096, @dir.filesize
64
+ assert_equal 531, @file.filesize
65
+ assert_equal 4096, @other_dir.filesize
66
+ assert_equal 72, @spaces.filesize
67
+ assert_equal 4, @symlink.filesize
68
+ assert_equal 154112, @older_date.filesize
69
+ end
55
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-ftp-list
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stateless Systems
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-05 00:00:00 +10:00
12
+ date: 2010-07-30 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,6 +22,7 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - README.txt
24
24
  files:
25
+ - .gitignore
25
26
  - README.txt
26
27
  - Rakefile
27
28
  - VERSION.yml
@@ -30,6 +31,7 @@ files:
30
31
  - lib/net/ftp/list/netware.rb
31
32
  - lib/net/ftp/list/parser.rb
32
33
  - lib/net/ftp/list/unix.rb
34
+ - net-ftp-list.gemspec
33
35
  - test/test_net_ftp_list_microsoft.rb
34
36
  - test/test_net_ftp_list_netware.rb
35
37
  - test/test_net_ftp_list_unix.rb
@@ -59,9 +61,9 @@ requirements: []
59
61
  rubyforge_project:
60
62
  rubygems_version: 1.3.5
61
63
  signing_key:
62
- specification_version: 2
64
+ specification_version: 3
63
65
  summary: Parse FTP LIST command output.
64
66
  test_files:
67
+ - test/test_net_ftp_list_microsoft.rb
65
68
  - test/test_net_ftp_list_unix.rb
66
69
  - test/test_net_ftp_list_netware.rb
67
- - test/test_net_ftp_list_microsoft.rb