Class: FileTransferMixin::Interfaces::SFTP

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

Instance Method Summary collapse

Instance Method Details

#configurationObject



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

def configuration
  FileTransferMixin.configuration.sftp
end

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



40
41
42
43
44
# File 'lib/file_transfer_mixin/interfaces/sftp.rb', line 40

def perform(action, key, *args)
  sftp_block(key) do |sftp|
    sftp.send(action, *args)
  end
end

#perform_network_operations?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/file_transfer_mixin/interfaces/sftp.rb', line 46

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

#sftp_block(key, &block) ⇒ Object



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

def sftp_block(key, &block)
  if perform_network_operations?
    c = configuration[key]
    Net::SFTP.start(c[:server], c[:username], :password => c[:password]) do |sftp|
      yield(sftp)
    end
  end
end

#sftp_fetch(key, remote_path, local_path) ⇒ Object



32
33
34
# File 'lib/file_transfer_mixin/interfaces/sftp.rb', line 32

def sftp_fetch(key, remote_path, local_path)
  perform :download!, key, remote_path, local_path
end

#sftp_move(key, original_remote_path, new_remote_path) ⇒ Object



36
37
38
# File 'lib/file_transfer_mixin/interfaces/sftp.rb', line 36

def sftp_move(key, original_remote_path, new_remote_path)
  perform :rename!, key, original_remote_path, new_remote_path
end

#sftp_send(key, remote_path, local_path) ⇒ Object



28
29
30
# File 'lib/file_transfer_mixin/interfaces/sftp.rb', line 28

def sftp_send(key, remote_path, local_path)
  perform :upload!, key, local_path, remote_path
end