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_network_operations?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/file_transfer_mixin/interfaces/sftp.rb', line 39

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

#sftp_block(key, &block) ⇒ Object



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

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

#sftp_fetch(key, remote_path, local_path) ⇒ Object



33
34
35
36
37
# File 'lib/file_transfer_mixin/interfaces/sftp.rb', line 33

def sftp_fetch(key, remote_path, local_path)
  sftp_block(key) do |sftp|
    sftp.download!(remote_path, local_path)
  end
end

#sftp_send(key, remote_path, local_path) ⇒ Object



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

def sftp_send(key, remote_path, local_path)
  sftp_block(key) do |sftp|
    sftp.upload!(local_path, remote_path)
  end
end