Class: Fastlane::Sftp::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/sftp/helper/downloader.rb

Overview

Responsible for performing download SFTP operation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Downloader

Returns a new instance of Downloader.



28
29
30
31
32
33
34
35
36
37
# File 'lib/fastlane/plugin/sftp/helper/downloader.rb', line 28

def initialize(options)
  self.options = options unless options.nil?
  self.host = options[:server_url]
  self.user = options[:server_user]
  self.password = options[:server_password]
  self.rsa_keypath = options[:server_key]
  self.rsa_keypath_passphrase = options[:server_key_passphrase]
  self.files = options[:file_paths]
  self.target_dir = options[:target_dir]
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



26
27
28
# File 'lib/fastlane/plugin/sftp/helper/downloader.rb', line 26

def files
  @files
end

#hostObject

These want to be an input parameters:



19
20
21
# File 'lib/fastlane/plugin/sftp/helper/downloader.rb', line 19

def host
  @host
end

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/fastlane/plugin/sftp/helper/downloader.rb', line 13

def options
  @options
end

#passwordObject

Returns the value of attribute password.



21
22
23
# File 'lib/fastlane/plugin/sftp/helper/downloader.rb', line 21

def password
  @password
end

#root_pathObject

Returns the value of attribute root_path.



25
26
27
# File 'lib/fastlane/plugin/sftp/helper/downloader.rb', line 25

def root_path
  @root_path
end

#rsa_keypathObject

Returns the value of attribute rsa_keypath.



22
23
24
# File 'lib/fastlane/plugin/sftp/helper/downloader.rb', line 22

def rsa_keypath
  @rsa_keypath
end

#rsa_keypath_passphraseObject

Returns the value of attribute rsa_keypath_passphrase.



23
24
25
# File 'lib/fastlane/plugin/sftp/helper/downloader.rb', line 23

def rsa_keypath_passphrase
  @rsa_keypath_passphrase
end

#target_dirObject

Returns the value of attribute target_dir.



24
25
26
# File 'lib/fastlane/plugin/sftp/helper/downloader.rb', line 24

def target_dir
  @target_dir
end

#userObject

Returns the value of attribute user.



20
21
22
# File 'lib/fastlane/plugin/sftp/helper/downloader.rb', line 20

def user
  @user
end

Instance Method Details

#downloadObject

Download files



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fastlane/plugin/sftp/helper/downloader.rb', line 43

def download
  # Login & Download all files using RSA key or username/password
  UI.message('download...')
  session = Helper::SftpHelper.(host, user, password, rsa_keypath, rsa_keypath_passphrase)
  if session.nil?
    return false
  end
  UI.message('Downloading files...')

  session.sftp.connect do |sftp|
    source_files = files.map { |entry| Helper::SftpHelper.generate_remote_path(user, entry) }
    downloads = sftp_download(sftp, source_files, target_dir)
    downloads.each(&:wait)

    # Lists the entries in a directory for verification
    Dir.entries(target_dir).each do |entry|
      UI.message(entry)
    end
  end
  session.close
  return true
end