net-ftp-walk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8305eb04c5be62af3327b95b895fef82f056591f
4
+ data.tar.gz: d27fd9a66dae5a7ae16f57586d9a20a22d2c4cda
5
+ SHA512:
6
+ metadata.gz: 04ddfec9f93701f1c7a6d482ed63ee20924fcfe90184fe468e3554f7944e4f8888114523f41d8c74e7fb1b6dd362f9ee6e69818020c978d0aa36c3a495e60a42
7
+ data.tar.gz: bdfe463bf826c037d81520a35f3f3d046057bf9988042078225514f9f40818b129d5187aa9964fcf6d1f4b997a54fd828ef06aa2a1724a257ba5f9891babea61
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in net-ftp-walk.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # net-ftp-walk
2
+
3
+ walks a FTP directory, also supports "du" and mirroring
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'net-ftp-walk'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install net-ftp-walk
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/net-ftp-walk/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,56 @@
1
+ require 'net/ftp/list'
2
+
3
+ class Net::FTP
4
+ def walk(dir, parser_class = Net::FTP::List, &block)
5
+ paths = [ dir ]
6
+
7
+ while paths.count > 0 do
8
+ path = paths.pop
9
+
10
+ self.list(path) do |e|
11
+ entry = parser_class.parse(e)
12
+
13
+ if entry.dir? then
14
+ unless ['.', '..'].include? entry.basename then
15
+ paths << path + '/' + entry.basename
16
+ end
17
+ else
18
+ yield path, entry
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ def du(dir, block_size = 4096, parser_class = Net::FTP::List)
25
+ sum = 0
26
+
27
+ walk(dir, parser_class) do |path, entry|
28
+ sum += (entry.filesize + block_size - 1) / block_size * block_size
29
+ end
30
+
31
+ sum
32
+ end
33
+
34
+ def mirror(remote_dir, local_dir, parser_class = Net::FTP::List)
35
+ queue = []
36
+
37
+ walk(remote_dir, parser_class) do |path, entry|
38
+ common_path = path[remote_dir.length + 1 .. -1]
39
+
40
+ remote_file = remote_dir + '/' + common_path + '/' + entry.basename
41
+ local_file = local_dir + '/' + common_path + '/' + entry.basename
42
+
43
+ if File.exist?(local_file)
44
+ next if File.size(local_file) == entry.filesize && File.mtime(local_file) == entry.mtime
45
+ end
46
+
47
+ queue << [remote_file, local_file, entry.mtime]
48
+ end
49
+
50
+ queue.each do |item|
51
+ getbinaryfile(item[0], item[1])
52
+
53
+ File.utime(item[2], item[2], item[1])
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "net-ftp-walk"
5
+ spec.version = "1.0.0"
6
+ spec.authors = ["Toru Nayuki"]
7
+ spec.email = ["tnayuki@icloud.com"]
8
+ spec.summary = "walks a FTP directory, also supports \"du\" and mirroring"
9
+ spec.homepage = "https://github.com/tnayuki/net-ftp-walk/"
10
+ spec.license = "MIT"
11
+
12
+ spec.files = `git ls-files -z`.split("\x0")
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "net-ftp-list"
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.5"
20
+ spec.add_development_dependency "rake"
21
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: net-ftp-walk
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Toru Nayuki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ftp-list
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - tnayuki@icloud.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/net/ftp/walk.rb
68
+ - net-ftp-walk.gemspec
69
+ homepage: https://github.com/tnayuki/net-ftp-walk/
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.0.14
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: walks a FTP directory, also supports "du" and mirroring
93
+ test_files: []