Class: MPW::FTP

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ FTP

Constructor @args: config -> the config



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

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
44
# File 'lib/mpw/sync/ftp.rb', line 37

def connect
  Net::FTP.open(@host) do |ftp|
    ftp.(@user, @password)
    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



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

def get(file_tmp)
  Net::FTP.open(@host) do |ftp|
    ftp.(@user, @password)
    ftp.gettextfile(@path, file_tmp)
  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
66
# File 'lib/mpw/sync/ftp.rb', line 59

def update(file_gpg)
  Net::FTP.open(@host) do |ftp|
    ftp.(@user, @password)
    ftp.puttextfile(file_gpg, @path)
  end
rescue Exception => e
  raise "#{I18n.t('error.sync.upload')}\n#{e}"
end