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.



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fastlane/plugin/sftp/helper/uploader.rb', line 30

def initialize(options)
  self.options = options unless options.nil?
  self.host = options[:server_url]
  self.port = options[:server_port]
  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]
  self.delete_target_dir = options[:delete_target_dir]
end

Instance Attribute Details

#delete_target_dirObject

Returns the value of attribute delete_target_dir.



28
29
30
# File 'lib/fastlane/plugin/sftp/helper/uploader.rb', line 28

def delete_target_dir
  @delete_target_dir
end

#filesObject

Returns the value of attribute files.



27
28
29
# File 'lib/fastlane/plugin/sftp/helper/uploader.rb', line 27

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.



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

def password
  @password
end

#portObject

Returns the value of attribute port.



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

def port
  @port
end

#root_pathObject

Returns the value of attribute root_path.



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

def root_path
  @root_path
end

#rsa_keypathObject

Returns the value of attribute rsa_keypath.



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

def rsa_keypath
  @rsa_keypath
end

#rsa_keypath_passphraseObject

Returns the value of attribute rsa_keypath_passphrase.



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

def rsa_keypath_passphrase
  @rsa_keypath_passphrase
end

#target_dirObject

Returns the value of attribute target_dir.



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

def target_dir
  @target_dir
end

#userObject

Returns the value of attribute user.



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

def user
  @user
end

Instance Method Details

#uploadObject

Upload files



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
76
# File 'lib/fastlane/plugin/sftp/helper/uploader.rb', line 47

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

  session = Helper::SftpHelper.(host, port, user, password, rsa_keypath, rsa_keypath_passphrase)
  UI.message('Uploading files...')

  session.sftp.connect do |sftp|
    Helper::SftpHelper.remote_rmdir(sftp, target_dir) if delete_target_dir
    Helper::SftpHelper.remote_mkdir(sftp, 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(target_dir) do |entry|
      UI.message(entry.longname)
    end
  end
  session.close
  return true
end