Class: MPW::SyncSSH

Inherits:
Object
  • Object
show all
Defined in:
lib/mpw/sync/ssh.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ SyncSSH

Constructor @args: config -> the config



28
29
30
31
32
33
34
# File 'lib/mpw/sync/ssh.rb', line 28

def initialize(config)
	@host      = config['host']
	@user      = config['user']
	@password  = config['password']
	@path      = config['path']
	@port      = config['port'].instance_of?(Integer) ? 22 : config['port']
end

Instance Method Details

#connectObject

Connect to server



37
38
39
40
41
42
43
# File 'lib/mpw/sync/ssh.rb', line 37

def connect
	Net::SSH.start(@host, @user, password: @password, port: @port) do
		break
	end
rescue Exception => e
	raise "#{I18n.t('error.sync.connection')}\n#{e}"
end

#get(file_tmp) ⇒ Object

Get data on server @args: file_tmp -> the path where download the file



47
48
49
50
51
52
53
54
55
# File 'lib/mpw/sync/ssh.rb', line 47

def get(file_tmp)
	Net::SFTP.start(@host, @user, password: @password, port: @port) do |sftp|
		sftp.lstat(@path) do |response|
			sftp.download!(@path, file_tmp) if response.ok?
		end
	end
rescue Exception => e
	raise "#{I18n.t('error.sync.download')}\n#{e}"
end

#update(file_gpg) ⇒ Object

Update the remote data @args: file_gpg -> the data to send on server



59
60
61
62
63
64
65
# File 'lib/mpw/sync/ssh.rb', line 59

def update(file_gpg)
	Net::SFTP.start(@host, @user, password: @password, port: @port) do |sftp|
		sftp.upload!(file_gpg, @path)
	end
rescue Exception => e
	raise "#{I18n.t('error.sync.upload')}\n#{e}"
end