Class: DRbQS::Transfer::Client::SFTP

Inherits:
Base
  • Object
show all
Defined in:
lib/drbqs/utility/transfer/transfer_client_connect.rb

Overview

Transfer files to directory on DRbQS server over sftp. Note that after we transfer files we delete the original files.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, host, directory) ⇒ SFTP

Returns a new instance of SFTP.



28
29
30
31
32
# File 'lib/drbqs/utility/transfer/transfer_client_connect.rb', line 28

def initialize(user, host, directory)
  super(directory)
  @user = user
  @host = host
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



26
27
28
# File 'lib/drbqs/utility/transfer/transfer_client_connect.rb', line 26

def directory
  @directory
end

#hostObject (readonly)

Returns the value of attribute host.



26
27
28
# File 'lib/drbqs/utility/transfer/transfer_client_connect.rb', line 26

def host
  @host
end

#userObject (readonly)

Returns the value of attribute user.



26
27
28
# File 'lib/drbqs/utility/transfer/transfer_client_connect.rb', line 26

def user
  @user
end

Instance Method Details

#download(files) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/drbqs/utility/transfer/transfer_client_connect.rb', line 51

def download(files)
  moved = []
  start_sftp do |sftp|
    files.each do |path|
      dir, downloaded_path = directory_for_download(path)
      sftp.download(path, dir, :recursive => true)
      moved << downloaded_path
    end
  end
  moved
rescue => err
  raise err.class, "user=#{@user}, host=#{@host}, directory=#{@directory}; #{err.to_s}", err.backtrace 
end

#transfer(files) ⇒ Object

Transfer and delete +files+.



40
41
42
43
44
45
46
47
48
49
# File 'lib/drbqs/utility/transfer/transfer_client_connect.rb', line 40

def transfer(files)
  start_sftp do |sftp|
    files.each do |path|
      sftp.upload(path, upload_name(path))
      FileUtils.rm_r(path)
    end
  end
rescue => err
  raise err.class, "user=#{@user}, host=#{@host}, directory=#{@directory}; #{err.to_s}", err.backtrace 
end