Class: FileTransferMixin::Interfaces::FTP

Inherits:
Object
  • Object
show all
Defined in:
lib/file_transfer_mixin/interfaces/ftp.rb

Instance Method Summary collapse

Instance Method Details

#configurationObject



15
16
17
# File 'lib/file_transfer_mixin/interfaces/ftp.rb', line 15

def configuration
  FileTransferMixin.configuration.ftp
end

#ftp_block(key, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/file_transfer_mixin/interfaces/ftp.rb', line 19

def ftp_block(key, &block)
  if perform_network_operations?
    c = configuration[key]
    Net::FTP.open(c[:server]) do |ftp|
      ftp.(c[:username], c[:password])
      yield(ftp)
    end
  end
end

#ftp_fetch(key, remote_path, local_path) ⇒ Object



33
34
35
# File 'lib/file_transfer_mixin/interfaces/ftp.rb', line 33

def ftp_fetch(key, remote_path, local_path)
  perform :getbinaryfile, key, remote_path, local_path
end

#ftp_move(key, original_remote_path, new_remote_path) ⇒ Object



37
38
39
# File 'lib/file_transfer_mixin/interfaces/ftp.rb', line 37

def ftp_move(key, original_remote_path, new_remote_path)
  perform :rename, key, original_remote_path, new_remote_path
end

#ftp_send(key, remote_path, local_path) ⇒ Object



29
30
31
# File 'lib/file_transfer_mixin/interfaces/ftp.rb', line 29

def ftp_send(key, remote_path, local_path)
  perform :putbinaryfile, key, local_path, remote_path
end

#perform(action, key, *args) ⇒ Object



41
42
43
44
45
# File 'lib/file_transfer_mixin/interfaces/ftp.rb', line 41

def perform(action, key, *args)
  ftp_block(key) do |ftp|
    ftp.send(action, *args)
  end
end

#perform_network_operations?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/file_transfer_mixin/interfaces/ftp.rb', line 47

def perform_network_operations?
  FileTransferMixin.env.to_s != 'test'
end