class FTPRepository

Attributes

ftps_host[R]
ftps_password[R]
ftps_remote_path[R]
ftps_username[R]

Public Class Methods

new(host, config) click to toggle source
# File lib/fastlane/plugin/carthage_cache_ftps/helper/ftp_repository.rb, line 9
def initialize(host, config)
  @ftps_host = config[:region]
  @ftps_remote_path = host
  @ftps_username = config[:aws_access_key_id]
  @ftps_password = config[:secret_access_key]
end

Public Instance Methods

archive_exist?(archive_filename) click to toggle source
# File lib/fastlane/plugin/carthage_cache_ftps/helper/ftp_repository.rb, line 25
def archive_exist?(archive_filename)
  ftps = connection
  begin
    ftps.chdir(@ftps_remote_path)
  rescue StandardError
    return false
  end
  files = ftps.list
  ftps.close

  if files.select { |f| f.include? archive_filename.to_s }.empty?
    return false
  else
    puts "Remote File already exists"
    return true
  end
end
connection() click to toggle source
# File lib/fastlane/plugin/carthage_cache_ftps/helper/ftp_repository.rb, line 16
def connection
  Net::FTP.new(@ftps_host, {
    ssl:      { verify_mode: OpenSSL::SSL::VERIFY_NONE },
    passive:  true,
    username: @ftps_username,
    password: @ftps_password
  })
end
download(archive_filename, destination_path) click to toggle source
# File lib/fastlane/plugin/carthage_cache_ftps/helper/ftp_repository.rb, line 43
def download(archive_filename, destination_path)
  ftps = connection
  ftps.getbinaryfile("#{@ftps_remote_path}/#{archive_filename}", destination_path)
  ftps.close
end
upload(archive_filename, archive_path) click to toggle source
# File lib/fastlane/plugin/carthage_cache_ftps/helper/ftp_repository.rb, line 49
def upload(archive_filename, archive_path)
  ftps = connection
  files = ftps.list

  if files.select { |f| f.include? @ftps_remote_path }.empty?
    ftps.mkdir(@ftps_remote_path)
  end

  remote_path = "#{@ftps_remote_path}/#{archive_filename}"
  if files.select { |f| f.include? remote_path }.empty?
    ftps.putbinaryfile(archive_path, remote_path)
  else
    puts "File #{remote_path} already exists"
  end

  ftps.close
end