Class: Infrataster::Contexts::FtpContext

Inherits:
BaseContext
  • Object
show all
Defined in:
lib/infrataster/contexts/ftp_context.rb

Overview

FTP Context

Instance Method Summary collapse

Instance Method Details

#resultObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/infrataster/contexts/ftp_context.rb', line 8

def result
  options = {}
  if server.options[:ftp]
    options = options.merge(server.options[:ftp])
  end

  resource.ftp = Net::FTP.open(server.address,
                               user = options[:user],
                               pass = options[:pass],
                               acct = nil)

  command, argument = resource.command.split

  response = ''
  if resource.ftp.respond_to?(command)
    response = resource.ftp.method(command).call if argument.nil?
    response = resource.ftp.method(command).call(argument) if argument
    resource.ftp.method('close').call
  end
  return response.join if response.is_a?(Array)
  response
end