mpw 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,67 +0,0 @@
1
- #!/usr/bin/ruby
2
- # MPW is a software to crypt and manage your passwords
3
- # Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
4
- #
5
- # This program is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU General Public License
7
- # as published by the Free Software Foundation; either version 2
8
- # of the License, or (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License
16
- # along with this program; if not, write to the Free Software
17
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
-
19
- require 'i18n'
20
- require 'net/ssh'
21
- require 'net/sftp'
22
-
23
- module MPW
24
- class SyncSSH
25
-
26
- # Constructor
27
- # @args: config -> the config
28
- def initialize(config)
29
- @host = config['host']
30
- @user = config['user']
31
- @password = config['password']
32
- @path = config['path']
33
- @port = config['port'].instance_of?(Integer) ? 22 : config['port']
34
- end
35
-
36
- # Connect to server
37
- def connect
38
- Net::SSH.start(@host, @user, password: @password, port: @port) do
39
- break
40
- end
41
- rescue Exception => e
42
- raise "#{I18n.t('error.sync.connection')}\n#{e}"
43
- end
44
-
45
- # Get data on server
46
- # @args: file_tmp -> the path where download the file
47
- def get(file_tmp)
48
- Net::SFTP.start(@host, @user, password: @password, port: @port) do |sftp|
49
- sftp.lstat(@path) do |response|
50
- sftp.download!(@path, file_tmp) if response.ok?
51
- end
52
- end
53
- rescue Exception => e
54
- raise "#{I18n.t('error.sync.download')}\n#{e}"
55
- end
56
-
57
- # Update the remote data
58
- # @args: file_gpg -> the data to send on server
59
- def update(file_gpg)
60
- Net::SFTP.start(@host, @user, password: @password, port: @port) do |sftp|
61
- sftp.upload!(file_gpg, @path)
62
- end
63
- rescue Exception => e
64
- raise "#{I18n.t('error.sync.upload')}\n#{e}"
65
- end
66
- end
67
- end