Class: MPW::FTP
- Inherits:
-
Object
- Object
- MPW::FTP
- Defined in:
- lib/mpw/sync/ftp.rb
Instance Attribute Summary collapse
-
#enable ⇒ Object
Returns the value of attribute enable.
-
#error_msg ⇒ Object
Returns the value of attribute error_msg.
Instance Method Summary collapse
-
#connect ⇒ Object
Connect to server @rtrn: false if the connection fail.
-
#get(file_tmp) ⇒ Object
Get data on server @args: gpg_password -> the gpg password @rtrn: nil if nothing data or error.
-
#initialize(host, user, password, path, port = nil) ⇒ FTP
constructor
Constructor @args: host -> the server host port -> ther connection port gpg_key -> the gpg key password -> the remote password suffix -> the suffix file.
-
#update(file_gpg) ⇒ Object
Update the remote data @args: data -> the data to send on server @rtrn: false if there is a problem.
Constructor Details
#initialize(host, user, password, path, port = nil) ⇒ FTP
Constructor @args: host -> the server host
port -> ther connection port
gpg_key -> the gpg key
password -> the remote password
suffix -> the suffix file
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mpw/sync/ftp.rb', line 21 def initialize(host, user, password, path, port=nil) @error_msg = nil @enable = false @host = host @user = user @password = password @path = path @port = port.instance_of?(Integer) ? 21 : port end |
Instance Attribute Details
#enable ⇒ Object
Returns the value of attribute enable.
13 14 15 |
# File 'lib/mpw/sync/ftp.rb', line 13 def enable @enable end |
#error_msg ⇒ Object
Returns the value of attribute error_msg.
12 13 14 |
# File 'lib/mpw/sync/ftp.rb', line 12 def error_msg @error_msg end |
Instance Method Details
#connect ⇒ Object
Connect to server @rtrn: false if the connection fail
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mpw/sync/ftp.rb', line 34 def connect Net::FTP.open(@host) do |ftp| ftp.login(@user, @password) @enable = true end rescue Exception => e @error_msg = "#{I18n.t('error.sync.connection')}\n#{e}" @enable = false else return @enable end |
#get(file_tmp) ⇒ Object
Get data on server @args: gpg_password -> the gpg password @rtrn: nil if nothing data or error
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mpw/sync/ftp.rb', line 49 def get(file_tmp) return false if not @enable Net::FTP.open(@host) do |ftp| ftp.login(@user, @password) ftp.gettextfile(@path, file_tmp) end return true rescue Exception => e @error_msg = "#{I18n.t('error.sync.download')}\n#{e}" return false end |
#update(file_gpg) ⇒ Object
Update the remote data @args: data -> the data to send on server @rtrn: false if there is a problem
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mpw/sync/ftp.rb', line 66 def update(file_gpg) return true if not @enable Net::FTP.open(@host) do |ftp| ftp.login(@user, @password) ftp.puttextfile(file_gpg, @path) end return true rescue Exception => e @error_msg = "#{I18n.t('error.sync.upload')}\n#{e}" return false end |