Sha256: f3d7afc8ff2abc277f5ab139cbf2eb56c022930a1e6f578196c6d44de158dfcb

Contents?: true

Size: 724 Bytes

Versions: 2

Compression:

Stored size: 724 Bytes

Contents

class PgExport
  class FtpAdapter
    extend Forwardable

    CHUNK_SIZE = (2**16).freeze

    def_delegators :connection, :ftp, :host

    def initialize(connection)
      @connection = connection
      ObjectSpace.define_finalizer(self, proc { connection.close })
    end

    def list(regex_string)
      ftp.list(regex_string).map { |item| item.split(' ').last }.sort.reverse
    end

    def delete(filename)
      ftp.delete(filename)
    end

    def upload_file(path, name)
      ftp.putbinaryfile(path.to_s, name, CHUNK_SIZE)
    end

    def download_file(path, name)
      ftp.getbinaryfile(name, path.to_s, CHUNK_SIZE)
    end

    def to_s
      host
    end

    private

    attr_reader :connection
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pg_export-0.5.1 lib/pg_export/services/ftp_adapter.rb
pg_export-0.5.0 lib/pg_export/services/ftp_adapter.rb