Sha256: 343b282288c513c5e4071587c76ed95e785119ea354ab3cc3c5138e63ce67481

Contents?: true

Size: 733 Bytes

Versions: 2

Compression:

Stored size: 733 Bytes

Contents

require 'net/ftp'

class PgExport
  module Ftp
    class Connection
      attr_reader :host

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

      def ftp
        open_ftp_thread.join
        @ftp
      end

      def close
        ftp.close
        logger.info 'Close FTP'
        self
      end

      private

      attr_reader :user, :password, :logger

      def open
        @ftp = Net::FTP.new(host, user, password)
        @ftp.passive = true
        logger.info "Connect to #{host}"
        self
      end

      def open_ftp_thread
        @open_ftp_thread ||= Thread.new { open }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pg_export-0.6.1 lib/pg_export/ftp/connection.rb
pg_export-0.6.0 lib/pg_export/ftp/connection.rb