Class: EasyBackup::Resources::SFTP

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_backup/resources/sftp.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ SFTP

Returns a new instance of SFTP.



5
6
7
# File 'lib/easy_backup/resources/sftp.rb', line 5

def initialize(&block)
  instance_eval &block if block_given?
end

Instance Method Details

#folder(folder = nil) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/easy_backup/resources/sftp.rb', line 21

def folder(folder=nil)
  if folder
    @folder = folder
  else
    @folder.is_a?(Proc) ? @folder.call : @folder
  end
end

#host(host = nil) ⇒ Object



9
10
11
# File 'lib/easy_backup/resources/sftp.rb', line 9

def host(host=nil)
  host ? @host = host : @host
end

#password(password = nil) ⇒ Object



17
18
19
# File 'lib/easy_backup/resources/sftp.rb', line 17

def password(password=nil)
  password ? @password = password : @password
end

#save(resource) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/easy_backup/resources/sftp.rb', line 29

def save(resource)
  Net::SFTP.start(host, username, :password => password) do |sftp|
    sftp_folder = folder
    EasyBackup.configuration.logger.info "[EasyBackup] Saving #{resource} into #{host} | #{username} | #{sftp_folder}"

    sftp.mkpath! sftp_folder, :progress => SFTPHandler.new
    sftp.upload! resource, "#{sftp_folder}/#{File.basename(resource)}", :progress => SFTPHandler.new
  end
end

#username(username = nil) ⇒ Object



13
14
15
# File 'lib/easy_backup/resources/sftp.rb', line 13

def username(username=nil)
  username ? @username = username : @username
end