Class: Backup::Storage::SFTP

Inherits:
Object
  • Object
show all
Defined in:
lib/backup/storage/sftp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter) ⇒ SFTP

Stores the backup file on the remote server using SFTP



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/backup/storage/sftp.rb', line 8

def initialize(adapter)
  %w(ip user password path).each do |method|
    send("#{method}=", adapter.procedure.get_storage_configuration.attributes[method])
  end
  
  final_file = adapter.final_file
  tmp_path   = adapter.tmp_path
  
  Net::SFTP.start(ip, user, :password => password) do |sftp|
    begin
      puts "Storing \"#{final_file}\" to path \"#{path}\" on remote server (#{ip})."
      sftp.upload!(File.join(tmp_path, final_file).gsub('\ ', ' '), File.join(path, final_file))
    rescue
      puts "Could not find \"#{path}\" on \"#{ip}\", please ensure this directory exists."
      exit
    end
  end
end

Instance Attribute Details

#final_fileObject

Returns the value of attribute final_file.



5
6
7
# File 'lib/backup/storage/sftp.rb', line 5

def final_file
  @final_file
end

#ipObject

Returns the value of attribute ip.



5
6
7
# File 'lib/backup/storage/sftp.rb', line 5

def ip
  @ip
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/backup/storage/sftp.rb', line 5

def password
  @password
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/backup/storage/sftp.rb', line 5

def path
  @path
end

#tmp_pathObject

Returns the value of attribute tmp_path.



5
6
7
# File 'lib/backup/storage/sftp.rb', line 5

def tmp_path
  @tmp_path
end

#userObject

Returns the value of attribute user.



5
6
7
# File 'lib/backup/storage/sftp.rb', line 5

def user
  @user
end