Class: Fastlane::Sftp::Uploader

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

Overview

Responsible for performing upload SFTP operations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Uploader

Returns a new instance of Uploader.



28
29
30
31
32
33
34
35
36
37
# File 'lib/fastlane/plugin/sftp/helper/uploader.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/uploader.rb', line 26

def files
  @files
end

#hostObject

These want to be an input parameters:



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

def host
  @host
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#passwordObject

Returns the value of attribute password.



21
22
23
# File 'lib/fastlane/plugin/sftp/helper/uploader.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/uploader.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/uploader.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/uploader.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/uploader.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/uploader.rb', line 20

def user
  @user
end

Instance Method Details

#uploadObject

Upload files



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fastlane/plugin/sftp/helper/uploader.rb', line 43

def upload
  # Login & Upload all files using RSA key or username/password
  UI.message('upload...')

  session = Helper::SftpHelper.(host, user, password, rsa_keypath, rsa_keypath_passphrase)
  if session.nil?
    return false
  end
  UI.message('Uploading files...')
  session.sftp.connect do |sftp|
    Helper::SftpHelper.remote_mkdir(sftp, Helper::SftpHelper.generate_remote_path(user, target_dir))
    path = target_dir

    uploads = []
    files.each do |file|
      next unless Helper::SftpHelper.check_file(file)

      re = Helper::SftpHelper.get_target_file_path(file, target_dir)
      if File.directory?(file)
        Helper::SftpHelper.remote_mkdir(sftp, re)
      end
      uploads.push(upload_file(sftp, file, re))
    end
    uploads.each(&:wait)

    # Lists the entries in a directory for verification
    sftp.dir.foreach(path) do |entry|
      UI.message(entry.longname)
    end
  end
  session.close
  return true
end