Class: RServiceBus::ScpDownloadHelper
- Inherits:
-
Object
- Object
- RServiceBus::ScpDownloadHelper
- Defined in:
- lib/rservicebus/AppResource/ScpDownload.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #close ⇒ Object
- #delete(filepattern) ⇒ Object
- #download(destination) ⇒ Object
-
#initialize(uri) ⇒ ScpDownloadHelper
constructor
A new instance of ScpDownloadHelper.
Constructor Details
#initialize(uri) ⇒ ScpDownloadHelper
Returns a new instance of ScpDownloadHelper.
9 10 11 |
# File 'lib/rservicebus/AppResource/ScpDownload.rb', line 9 def initialize( uri ) @uri = uri end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/rservicebus/AppResource/ScpDownload.rb', line 7 def uri @uri end |
Instance Method Details
#close ⇒ Object
20 21 |
# File 'lib/rservicebus/AppResource/ScpDownload.rb', line 20 def close end |
#delete(filepattern) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rservicebus/AppResource/ScpDownload.rb', line 23 def delete( filepattern ) RServiceBus.log "Host: #{@uri.host}, User: #{@uri.user}, File Pattern: #{filepattern}, Source: #{@uri.path}", true regexp = Regexp.new filepattern unless filepattern.nil? Net::SSH.start( @uri.host, @uri.user ) do |ssh| ssh.sftp.connect do |sftp| sftp.dir.foreach(@uri.path) do |entry| next if entry.name == '.' || entry.name == '..' if filepattern.nil? || entry.name =~ regexp then puts "#{@uri.path}/#{entry.name}" r = sftp.remove("#{@uri.path}/#{entry.name}") r.wait end end end end end |
#download(destination) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/rservicebus/AppResource/ScpDownload.rb', line 13 def download( destination ) RServiceBus.log "Host: #{@uri.host}, User: #{@uri.user}, Source: #{@uri.path}, Destination: #{destination}", true Net::SCP.start( @uri.host, @uri.user ) do |scp| scp.download!( @uri.path, destination, :recursive => true ) end end |