Class: PgExport::Gateways::Ftp

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_export/gateways/ftp.rb

Constant Summary collapse

CHUNK_SIZE =
(2**16)

Instance Method Summary collapse

Constructor Details

#initialize(host:, user:, password:) ⇒ Ftp

Returns a new instance of Ftp.



10
11
12
# File 'lib/pg_export/gateways/ftp.rb', line 10

def initialize(host:, user:, password:)
  @host, @user, @password, @logger = host, user, password
end

Instance Method Details

#closeObject



24
25
26
# File 'lib/pg_export/gateways/ftp.rb', line 24

def close
  @ftp&.close
end

#delete(name) ⇒ Object



36
37
38
# File 'lib/pg_export/gateways/ftp.rb', line 36

def delete(name)
  ftp.delete(name)
end

#ftpObject



52
53
54
# File 'lib/pg_export/gateways/ftp.rb', line 52

def ftp
  @ftp ||= open
end

#get(file, name) ⇒ Object



44
45
46
# File 'lib/pg_export/gateways/ftp.rb', line 44

def get(file, name)
  ftp.getbinaryfile(name, file.path, CHUNK_SIZE)
end

#list(name) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/pg_export/gateways/ftp.rb', line 28

def list(name)
  ftp
    .list([name, '*'].join('_'))
    .map { |row| extracted_meaningful_attributes(row) }
    .sort_by { |item| item[:name] }
    .reverse
end

#openObject



14
15
16
17
18
# File 'lib/pg_export/gateways/ftp.rb', line 14

def open
  @ftp = Net::FTP.new(host, user, password)
  @ftp.passive = true
  @ftp
end

#persist(file, name) ⇒ Object



40
41
42
# File 'lib/pg_export/gateways/ftp.rb', line 40

def persist(file, name)
  ftp.putbinaryfile(file.path, name, CHUNK_SIZE)
end

#to_sObject



48
49
50
# File 'lib/pg_export/gateways/ftp.rb', line 48

def to_s
  host
end

#welcomeObject



20
21
22
# File 'lib/pg_export/gateways/ftp.rb', line 20

def welcome
  open.welcome
end