Class: DRbQS::Transfer::Client::SFTP
- 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
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #download(files) ⇒ Object
-
#initialize(user, host, directory) ⇒ SFTP
constructor
A new instance of SFTP.
-
#transfer(files) ⇒ Object
Transfer and delete +files+.
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
#directory ⇒ Object (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 |
#host ⇒ Object (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 |
#user ⇒ Object (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 |