Class: Koine::Filesystem::Adapters::Sftp

Inherits:
Base
  • Object
show all
Defined in:
lib/koine/filesystem/adapters/sftp.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Sftp

Returns a new instance of Sftp.

Parameters:

  • options (Hash)

    a hash containing the same options as Net::SFTP.start method plus username and password @see net-ssh.github.io/net-sftp/

Options Hash (options):

  • :session (The Net::SFTP::Session)

    if not given it tries to create a new one from the options

  • :hostname (String)

    the ftp hostname

  • :username (String)

    the ftp hostname

  • :password (String)

    the ftp password



20
21
22
23
24
25
26
27
28
# File 'lib/koine/filesystem/adapters/sftp.rb', line 20

def initialize(options)
  if options[:session]
    @session = options.delete(:session)
  else
    @hostname = options.delete(:hostname)
    @username = options.delete(:username)
    @options = options
  end
end

Instance Method Details

#list(path = nil, recursive: false) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/koine/filesystem/adapters/sftp.rb', line 30

def list(path = nil, recursive: false)
  path = format_path(path, '.')
  matcher = format_matcher(recursive)

  entries = []

  session.dir.glob(path, matcher) do |item|
    if item.name == '.' || item.name == '..'
      next
    end

    entries << from_result(item, path)
  end

  entries
end