Class: PgExport::FtpService
- Inherits:
-
Object
- Object
- PgExport::FtpService
- Defined in:
- lib/pg_export/services/ftp_service.rb,
lib/pg_export/services/ftp_service/connection.rb
Defined Under Namespace
Classes: Connection
Constant Summary collapse
- CHUNK_SIZE =
(2**16).freeze
Instance Method Summary collapse
- #delete(filename) ⇒ Object
-
#initialize(params) ⇒ FtpService
constructor
A new instance of FtpService.
- #list(regexp) ⇒ Object
- #to_s ⇒ Object
- #upload_file(path, name) ⇒ Object
Constructor Details
#initialize(params) ⇒ FtpService
Returns a new instance of FtpService.
5 6 7 8 9 10 |
# File 'lib/pg_export/services/ftp_service.rb', line 5 def initialize(params) @host = params.fetch(:host) connection = Connection.new(params) @ftp = connection.ftp ObjectSpace.define_finalizer(self, proc { connection.close }) end |
Instance Method Details
#delete(filename) ⇒ Object
16 17 18 |
# File 'lib/pg_export/services/ftp_service.rb', line 16 def delete(filename) ftp.delete(filename) end |
#list(regexp) ⇒ Object
12 13 14 |
# File 'lib/pg_export/services/ftp_service.rb', line 12 def list(regexp) ftp.list(regexp).map { |item| item.split(' ').last }.sort.reverse end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/pg_export/services/ftp_service.rb', line 24 def to_s host end |
#upload_file(path, name) ⇒ Object
20 21 22 |
# File 'lib/pg_export/services/ftp_service.rb', line 20 def upload_file(path, name) ftp.putbinaryfile(path.to_s, name, CHUNK_SIZE) end |