syncftp 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +18 -1
  2. data/VERSION +1 -1
  3. data/lib/syncftp.rb +38 -8
  4. data/syncftp.gemspec +4 -4
  5. metadata +16 -4
@@ -4,13 +4,25 @@ Sync via FTP, only modified files
4
4
 
5
5
  == ChangeLog
6
6
 
7
+ === 0.0.3 :
8
+
9
+ * Major bug correction in Net::FTP#remote_dir_exist?
10
+ * Remove deleted files and directories
11
+ * Additional option (passive => boolean) to determine the kind of FTP connection (passive/active)
12
+
13
+ === 0.0.2 :
14
+
15
+ * Major bug correction in Net::FTP#remote_dir_exist?
16
+ * If file type is unknow, we assume the file is binary...
17
+
7
18
  === 0.0.1 :
19
+
8
20
  * First Release
9
21
 
10
22
  == TODO
11
23
 
12
24
  * Allow to choose if we want to save the catalog locally or remotely
13
- * Remove deleted files
25
+ * Allow to synchronize from local to server, from server to local or both
14
26
 
15
27
  == Example
16
28
 
@@ -33,6 +45,11 @@ Sync via FTP, only modified files
33
45
 
34
46
  This lib was truly inspired by the awsome glynn (http://github.com/dmathieu/glynn)
35
47
 
48
+ == Authors
49
+
50
+ * Grégoire Lejeune <https://github.com/glejeune>
51
+ * danc <https://github.com/danc>
52
+
36
53
  == Copyright
37
54
 
38
55
  Copyright (c) 2010 Gregoire Lejeune. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -52,7 +52,11 @@ module Net
52
52
 
53
53
  return true if dir == "."
54
54
 
55
- nlst( path ).include?( find ) or nlst( path ).include?( dir ) or nlst( path ).include?( altdir )
55
+ begin
56
+ nlst( path ).include?( find ) or nlst( path ).include?( dir ) or nlst( path ).include?( altdir )
57
+ rescue Net::FTPTempError
58
+ return false
59
+ end
56
60
  end
57
61
 
58
62
  #
@@ -134,11 +138,12 @@ class SyncFTP
134
138
  # * +:remote+ : the remote directory (default = ".")
135
139
  #
136
140
  def sync( options = {} )
137
- options = { :local => ".", :remote => "." }.merge( options )
138
- local, remote = options[:local], options[:remote]
141
+ options = { :local => ".", :remote => "." , :passive => false}.merge( options )
142
+ local, remote , passive = options[:local], options[:remote], options[:passive]
139
143
 
140
144
  tmpname = tmpfilename
141
145
  connect do |ftp|
146
+ ftp.passive = passive
142
147
  # Read remote .syncftp
143
148
  begin
144
149
  ftp.gettextfile( remote+"/"+".syncftp", tmpname )
@@ -154,6 +159,26 @@ class SyncFTP
154
159
  File.open( tmpname, 'w' ) do |out|
155
160
  YAML.dump( @local_md5s, out )
156
161
  end
162
+
163
+ # Delete files
164
+ @delete_dirs = []
165
+ @delete_files = []
166
+ @remote_md5s.keys.clone.delete_if{ |f| @local_md5s.keys.include?(f) }.each do |f|
167
+ if @remote_md5s[f] == "*"
168
+ @delete_dirs << f
169
+ else
170
+ @delete_files << f
171
+ end
172
+ end
173
+ @delete_files.each do |f|
174
+ @log.info "Delete ftp://#{@host}:#{@port}/#{f}"
175
+ ftp.delete( f )
176
+ end
177
+ @delete_dirs.each do |f|
178
+ @log.info "Delete ftp://#{@host}:#{@port}/#{f}"
179
+ ftp.delete( f )
180
+ end
181
+
157
182
  ftp.puttextfile( tmpname, remote+"/"+".syncftp" )
158
183
  end
159
184
  File.delete( tmpname )
@@ -198,29 +223,34 @@ class SyncFTP
198
223
  end
199
224
 
200
225
  def send_dir(ftp, local, remote) #:nodoc:
201
- ftp.mkdir_p(remote) unless ftp.remote_dir_exist?(remote)
226
+ unless ftp.remote_dir_exist?(remote)
227
+ @log.info "Create directory ftp://#{@host}:#{@port}/#{remote}"
228
+ ftp.mkdir_p(remote)
229
+ end
202
230
 
203
231
  Dir.foreach(local) do |file|
204
232
  next if file == "." or file == ".."
205
233
 
206
234
  local_file = File.join( local, file )
207
235
  remote_file = remote + "/" + file
208
-
236
+
209
237
  if File.stat(local_file).directory?
210
238
  # It is a directory, we recursively send it
239
+ @local_md5s[remote_file] = "*"
211
240
  send_dir(ftp, local_file, remote_file)
212
241
  else
213
242
  @local_md5s[remote_file] = Digest::MD5.hexdigest( File.open(local_file).read )
214
-
243
+
244
+ # Local file still exist... Copy...
215
245
  if( @local_md5s[remote_file] != @remote_md5s[remote_file] )
216
246
  # It's a file, we just send it
217
247
  if File.binary?(local_file)
218
248
  @log.info "Copy [Binary] #{local_file} to ftp://#{@host}:#{@port}/#{remote_file}"
219
-
249
+
220
250
  ftp.putbinaryfile(local_file, remote_file)
221
251
  else
222
252
  @log.info "Copy [Text] #{local_file} to ftp://#{@host}:#{@port}/#{remote_file}"
223
-
253
+
224
254
  ftp.puttextfile(local_file, remote_file)
225
255
  end
226
256
  else
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{syncftp}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gregoire Lejeune"]
12
- s.date = %q{2010-04-15}
12
+ s.date = %q{2010-11-05}
13
13
  s.description = %q{Sync via FTP, only modified files}
14
14
  s.email = %q{gregoire.lejeune@free.fr}
15
15
  s.extra_rdoc_files = [
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
31
31
  s.homepage = %q{http://github.com/glejeune/syncftp}
32
32
  s.rdoc_options = ["--charset=UTF-8"]
33
33
  s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.3.6}
34
+ s.rubygems_version = %q{1.3.7}
35
35
  s.summary = %q{Sync via FTP, only modified files}
36
36
  s.test_files = [
37
37
  "test/helper.rb",
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
43
43
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
44
  s.specification_version = 3
45
45
 
46
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
47
  s.add_runtime_dependency(%q<mime-types>, [">= 0"])
48
48
  s.add_development_dependency(%q<shoulda>, [">= 0"])
49
49
  s.add_development_dependency(%q<fakefs>, [">= 0"])
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syncftp
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 2
9
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - Gregoire Lejeune
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-04-15 00:00:00 +02:00
18
+ date: 2010-11-05 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: mime-types
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
@@ -33,9 +36,11 @@ dependencies:
33
36
  name: shoulda
34
37
  prerelease: false
35
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
36
40
  requirements:
37
41
  - - ">="
38
42
  - !ruby/object:Gem::Version
43
+ hash: 3
39
44
  segments:
40
45
  - 0
41
46
  version: "0"
@@ -45,9 +50,11 @@ dependencies:
45
50
  name: fakefs
46
51
  prerelease: false
47
52
  requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
48
54
  requirements:
49
55
  - - ">="
50
56
  - !ruby/object:Gem::Version
57
+ hash: 3
51
58
  segments:
52
59
  - 0
53
60
  version: "0"
@@ -73,6 +80,7 @@ files:
73
80
  - syncftp.gemspec
74
81
  - test/helper.rb
75
82
  - test/test_syncftp.rb
83
+ - examples/sample01.rb
76
84
  has_rdoc: true
77
85
  homepage: http://github.com/glejeune/syncftp
78
86
  licenses: []
@@ -83,23 +91,27 @@ rdoc_options:
83
91
  require_paths:
84
92
  - lib
85
93
  required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
86
95
  requirements:
87
96
  - - ">="
88
97
  - !ruby/object:Gem::Version
98
+ hash: 3
89
99
  segments:
90
100
  - 0
91
101
  version: "0"
92
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
93
104
  requirements:
94
105
  - - ">="
95
106
  - !ruby/object:Gem::Version
107
+ hash: 3
96
108
  segments:
97
109
  - 0
98
110
  version: "0"
99
111
  requirements: []
100
112
 
101
113
  rubyforge_project:
102
- rubygems_version: 1.3.6
114
+ rubygems_version: 1.3.7
103
115
  signing_key:
104
116
  specification_version: 3
105
117
  summary: Sync via FTP, only modified files