class Outback::SftpTarget
Attributes
host[R]
Public Class Methods
new(backup_name, host)
click to toggle source
Calls superclass method
# File lib/outback/sftp_target.rb, line 9 def initialize(backup_name, host) super(backup_name) @host = host end
Public Instance Methods
put(archives)
click to toggle source
# File lib/outback/sftp_target.rb, line 22 def put(archives) size = count = 0 connect do archives.each do |archive| basename = archive.filename.basename.to_s upload_filename = path ? File.join(path, basename) : basename logger.debug "SftpTarget: storing #{archive.filename} in sftp://#{user}@#{host}#{':' + port.to_s if port}:#{upload_filename}" connection.upload!(archive.filename.to_s, upload_filename) size += archive.size count += 1 end end logger.info "Uploaded #{count} archives (#{size} bytes) to #{self}" count end
to_s()
click to toggle source
# File lib/outback/sftp_target.rb, line 18 def to_s "sftp:#{user}@#{host}#{':' + port.to_s if port}:#{path}" end
valid?()
click to toggle source
# File lib/outback/sftp_target.rb, line 14 def valid? host.present? end
Private Instance Methods
connect() { || ... }
click to toggle source
# File lib/outback/sftp_target.rb, line 40 def connect result = nil Net::SFTP.start(host, user, ssh_options) do |sftp| @connection = sftp result = yield end result ensure @connection = nil end
list_all_archives()
click to toggle source
# File lib/outback/sftp_target.rb, line 61 def list_all_archives connection.dir.entries(path).select(&:file?).map { |entry| build_archive(File.join(path, entry.name), entry.attributes.size.to_i) } end
ssh_options()
click to toggle source
# File lib/outback/sftp_target.rb, line 51 def ssh_options options = ssh_opts || {} if password options[:password] = password options[:auth_methods] ||= %w[password] end options[:port] = port if port options end
unlink_archive!(archive)
click to toggle source
# File lib/outback/sftp_target.rb, line 65 def unlink_archive!(archive) connection.remove!(archive.filename) end