syncftp 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +5 -0
- data/VERSION +1 -1
- data/lib/syncftp.rb +30 -5
- data/syncftp.gemspec +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
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
|
-
|
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 = {
|
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