syncftp 0.0.1 → 0.0.2

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 +5 -0
  2. data/VERSION +1 -1
  3. data/lib/syncftp.rb +30 -5
  4. data/syncftp.gemspec +1 -1
  5. metadata +2 -2
data/README.rdoc CHANGED
@@ -7,6 +7,11 @@ Sync via FTP, only modified files
7
7
  === 0.0.1 :
8
8
  * First Release
9
9
 
10
+ == TODO
11
+
12
+ * Allow to choose if we want to save the catalog locally or remotely
13
+ * Remove deleted files
14
+
10
15
  == Example
11
16
 
12
17
  require 'syncftp'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/syncftp.rb CHANGED
@@ -47,8 +47,12 @@ module Net
47
47
  find = path.pop
48
48
  path = path.join( "/" )
49
49
  path = "." if path == ""
50
+ altdir = dir
51
+ altdir = dir[2..-1] if dir[0,2] == "./"
50
52
 
51
- nlst( path ).include?( dir )
53
+ return true if dir == "."
54
+
55
+ nlst( path ).include?( find ) or nlst( path ).include?( dir ) or nlst( path ).include?( altdir )
52
56
  end
53
57
 
54
58
  #
@@ -83,6 +87,9 @@ class File
83
87
  # Check if the +file+ is a binary file
84
88
  #
85
89
  def self.binary?( file )
90
+ if MIME::Types.type_for( file ).size == 0
91
+ return true
92
+ end
86
93
  MIME::Types.type_for( file ).map{ |e| (e.binary?) ? e : nil }.compact.size > 0
87
94
  end
88
95
  end
@@ -102,9 +109,16 @@ class SyncFTP
102
109
  # * +:loglevel+ - default = Logger::UNKNOWN (Cool if you don't want logs)
103
110
  #
104
111
  def initialize(host, options = {})
105
- options = {:username => "anonymous", :password => nil, :logfile => STDOUT, :loglevel => Logger::UNKNOWN}.merge(options)
112
+ options = {
113
+ :username => "anonymous",
114
+ :password => nil,
115
+ :logfile => STDOUT,
116
+ :loglevel => Logger::UNKNOWN,
117
+ :catalog => :remote
118
+ }.merge(options)
106
119
  @host, @port = host, options[:port]||21
107
120
  @username, @password = options[:username], options[:password]
121
+ @catalog = options[:catalog]
108
122
  @remote_md5s = {}
109
123
  @local_md5s = {}
110
124
  @log = Logger.new( options[:logfile] )
@@ -145,6 +159,15 @@ class SyncFTP
145
159
  File.delete( tmpname )
146
160
  end
147
161
 
162
+ def getCatalog #:nodoc
163
+ end
164
+
165
+ def saveCatalog #:nodoc
166
+ end
167
+
168
+ def catalogFileName #:nodoc
169
+ end
170
+
148
171
  private
149
172
  def tmpfilename #:nodoc:
150
173
  tmpdir = Dir::tmpdir
@@ -175,7 +198,7 @@ class SyncFTP
175
198
  end
176
199
 
177
200
  def send_dir(ftp, local, remote) #:nodoc:
178
- ftp.mkdir_p(remote)
201
+ ftp.mkdir_p(remote) unless ftp.remote_dir_exist?(remote)
179
202
 
180
203
  Dir.foreach(local) do |file|
181
204
  next if file == "." or file == ".."
@@ -190,12 +213,14 @@ class SyncFTP
190
213
  @local_md5s[remote_file] = Digest::MD5.hexdigest( File.open(local_file).read )
191
214
 
192
215
  if( @local_md5s[remote_file] != @remote_md5s[remote_file] )
193
- @log.info "Copy #{local_file} to ftp://#{@host}:#{@port}/#{remote_file}"
194
-
195
216
  # It's a file, we just send it
196
217
  if File.binary?(local_file)
218
+ @log.info "Copy [Binary] #{local_file} to ftp://#{@host}:#{@port}/#{remote_file}"
219
+
197
220
  ftp.putbinaryfile(local_file, remote_file)
198
221
  else
222
+ @log.info "Copy [Text] #{local_file} to ftp://#{@host}:#{@port}/#{remote_file}"
223
+
199
224
  ftp.puttextfile(local_file, remote_file)
200
225
  end
201
226
  else
data/syncftp.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{syncftp}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
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"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Gregoire Lejeune