Class: PgExport::Adapters::FtpAdapter
- Inherits:
-
Object
- Object
- PgExport::Adapters::FtpAdapter
- Defined in:
- lib/pg_export/lib/pg_export/adapters/ftp_adapter.rb
Constant Summary collapse
- CHUNK_SIZE =
(2**16).freeze
Instance Method Summary collapse
- #close_ftp ⇒ Object
- #delete(filename) ⇒ Object
- #ftp ⇒ Object
- #get(file, name) ⇒ Object
-
#initialize(host:, user:, password:) ⇒ FtpAdapter
constructor
A new instance of FtpAdapter.
- #list(regex_string) ⇒ Object
- #open_ftp ⇒ Object
- #persist(file, name) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(host:, user:, password:) ⇒ FtpAdapter
Returns a new instance of FtpAdapter.
12 13 14 15 |
# File 'lib/pg_export/lib/pg_export/adapters/ftp_adapter.rb', line 12 def initialize(host:, user:, password:) @host, @user, @password, @logger = host, user, password ObjectSpace.define_finalizer(self, proc { ftp.close if @ftp }) end |
Instance Method Details
#close_ftp ⇒ Object
23 24 25 |
# File 'lib/pg_export/lib/pg_export/adapters/ftp_adapter.rb', line 23 def close_ftp @ftp&.close end |
#delete(filename) ⇒ Object
35 36 37 |
# File 'lib/pg_export/lib/pg_export/adapters/ftp_adapter.rb', line 35 def delete(filename) ftp.delete(filename) end |
#ftp ⇒ Object
51 52 53 |
# File 'lib/pg_export/lib/pg_export/adapters/ftp_adapter.rb', line 51 def ftp @ftp ||= open_ftp end |
#get(file, name) ⇒ Object
43 44 45 |
# File 'lib/pg_export/lib/pg_export/adapters/ftp_adapter.rb', line 43 def get(file, name) ftp.getbinaryfile(name, file.path, CHUNK_SIZE) end |
#list(regex_string) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/pg_export/lib/pg_export/adapters/ftp_adapter.rb', line 27 def list(regex_string) ftp .list(regex_string) .map { |row| extracted_meaningful_attributes(row) } .sort_by { |item| item[:name] } .reverse end |
#open_ftp ⇒ Object
17 18 19 20 21 |
# File 'lib/pg_export/lib/pg_export/adapters/ftp_adapter.rb', line 17 def open_ftp @ftp = Net::FTP.new(host, user, password) @ftp.passive = true @ftp end |
#persist(file, name) ⇒ Object
39 40 41 |
# File 'lib/pg_export/lib/pg_export/adapters/ftp_adapter.rb', line 39 def persist(file, name) ftp.putbinaryfile(file.path, name, CHUNK_SIZE) end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/pg_export/lib/pg_export/adapters/ftp_adapter.rb', line 47 def to_s host end |