Sha256: 5fd5dffc70b3de35684255aee2d1d85c1c1fc22047d46c2dfc4918633ff8b825

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

module Photocopier
  class FTP
    class Session
      def initialize(options)
        @scheme = options[:scheme]

        if sftp?
          @session = Net::SFTP.start(
            options[:host],
            options[:user],
            password: options[:password],
            port: options[:port] || 22
          )
        else
          @session = Net::FTP.open(
            options[:host],
            username: options[:user],
            password: options[:password],
            port: options[:port] || 21
          )
          @session.passive = options[:passive] if options.key?(:passive)
        end
      end

      def get(remote, local)
        if sftp?
          @session.download!(remote, local)
        else
          @session.get(remote, local)
        end
      end

      def put_file(local, remote)
        if sftp?
          @session.upload!(local, remote)
        else
          @session.put(local, remote)
        end
      end

      def delete(remote)
        if sftp?
          @session.remove!(remote)
        else
          @session.delete(remote)
        end
      end

      private

      def sftp?
        @scheme == 'sftp'
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
photocopier-1.3.0 lib/photocopier/ftp/session.rb
photocopier-1.3.0.pre3 lib/photocopier/ftp/session.rb
photocopier-1.3.0.pre2 lib/photocopier/ftp/session.rb