lib/webtranslateit/safe/ftp.rb in webtranslateit-safe-0.4.0 vs lib/webtranslateit/safe/ftp.rb in webtranslateit-safe-0.4.1
- old
+ new
@@ -1,9 +1,7 @@
module WebTranslateIt
-
module Safe
-
class Ftp < Sink
protected
def active?
@@ -13,48 +11,52 @@
def path
@path ||= expand(config[:ftp, :path] || config[:local, :path] || ':kind/:id')
end
def save
- raise 'pipe-streaming not supported for FTP.' unless @backup.path
+ raise RuntimeError, 'pipe-streaming not supported for FTP.' unless @backup.path
puts "Uploading #{host}:#{full_path} via FTP" if verbose? || dry_run?
- return if dry_run? || local_only?
-
- port ||= 21
- Net::FTP.open(host) do |ftp|
- ftp.connect(host, port)
- ftp.login(user, password)
- puts "Sending #{@backup.path} to #{full_path}" if verbose?
- begin
- ftp.put(@backup.path, full_path)
- rescue Net::FTPPermError
- puts "Ensuring remote path (#{path}) exists" if verbose?
+ unless dry_run? || local_only?
+ if !port
+ port = 21
end
+ Net::FTP.open(host) do |ftp|
+ ftp.connect(host, port)
+ ftp.login(user, password)
+ puts "Sending #{@backup.path} to #{full_path}" if verbose?
+ begin
+ ftp.put(@backup.path, full_path)
+ rescue Net::FTPPermError
+ puts "Ensuring remote path (#{path}) exists" if verbose?
+ end
+ end
+ puts '...done' if verbose?
end
- puts '...done' if verbose?
end
def cleanup
return if local_only? || dry_run?
- return unless (keep = config[:keep, :ftp])
+ return unless keep = config[:keep, :ftp]
puts "listing files: #{host}:#{base}*" if verbose?
- port ||= 21
+ if !port
+ port = 21
+ end
Net::FTP.open(host) do |ftp|
ftp.connect(host, port)
ftp.login(user, password)
files = ftp.nlst(path)
- pattern = File.basename(base.to_s)
- files = files.select { |x| x.start_with?(pattern) }
- puts(files.collect { |x| x }) if verbose?
+ pattern = File.basename("#{base}")
+ files = files.reject{ |x| !x.start_with?(pattern)}
+ puts files.collect {|x| x} if verbose?
- files = files
- .collect { |x| x }
- .sort
+ files = files.
+ collect {|x| x }.
+ sort
cleanup_with_limit(files, keep) do |f|
file = File.join(path, f)
puts "removing ftp file #{host}:#{file}" if dry_run? || verbose?
ftp.delete(file) unless dry_run? || local_only?
@@ -77,9 +79,7 @@
def port
config[:ftp, :port]
end
end
-
end
-
-end
+end
\ No newline at end of file