Class: Shenzhen::Plugins::FTP::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/shenzhen/plugins/ftp.rb

Direct Known Subclasses

SFTP::Client

Instance Method Summary collapse

Constructor Details

#initialize(host, port, user, password) ⇒ Client

Returns a new instance of Client.



8
9
10
# File 'lib/shenzhen/plugins/ftp.rb', line 8

def initialize(host, port, user, password)
  @host, @port, @user, @password = host, port, user, password
end

Instance Method Details

#upload(ipa, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/shenzhen/plugins/ftp.rb', line 12

def upload(ipa, options = {})
  connection = Net::FTP.new
  connection.passive = true
  connection.connect(@host, @port)

  path = expand_path_with_substitutions_from_ipa_plist(ipa, options[:path])

  begin
    connection.(@user, @password) rescue raise "Login authentication failed"

    if options[:mkdir]
      components, pwd = path.split(/\//).reject(&:empty?), nil
      components.each do |component|
        pwd = File.join(*[pwd, component].compact)

        begin
          connection.mkdir pwd
        rescue => exception
          raise exception unless /File exists/ === exception.message
        end
      end
    end

    connection.chdir path unless path.empty?
    connection.putbinaryfile ipa, File.basename(ipa)
    connection.putbinaryfile(options[:dsym], File.basename(options[:dsym])) if options[:dsym]
  ensure
    connection.close
  end
end