Class: RServiceBus::ScpUploadHelper
- Inherits:
-
Object
- Object
- RServiceBus::ScpUploadHelper
- Defined in:
- lib/rservicebus/AppResource/ScpUpload.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #close ⇒ Object
- #delete(path, filepattern) ⇒ Object
-
#initialize(uri) ⇒ ScpUploadHelper
constructor
A new instance of ScpUploadHelper.
- #upload(source) ⇒ Object
Constructor Details
#initialize(uri) ⇒ ScpUploadHelper
Returns a new instance of ScpUploadHelper.
9 10 11 |
# File 'lib/rservicebus/AppResource/ScpUpload.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/ScpUpload.rb', line 7 def uri @uri end |
Instance Method Details
#close ⇒ Object
23 24 |
# File 'lib/rservicebus/AppResource/ScpUpload.rb', line 23 def close end |
#delete(path, filepattern) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rservicebus/AppResource/ScpUpload.rb', line 26 def delete( path, filepattern ) RServiceBus.log "Host: #{@uri.host}, User: #{@uri.user}, File Pattern: #{filepattern}, Destination: #{@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(path) do |entry| next if entry.name == '.' || entry.name == '..' if filepattern.nil? || entry.name =~ regexp then r = sftp.remove("#{path}/#{entry.name}") r.wait end end end end end |
#upload(source) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/rservicebus/AppResource/ScpUpload.rb', line 13 def upload( source ) #opportunity for smarts here. Could tar zip if it was a directory of files #Net::SCP.upload!(@uri.host, @uri.user, source, @uri.path, :recursive ) RServiceBus.log "Host: #{@uri.host}, User: #{@uri.user}, Source: #{source}, Destination: #{@uri.path}", true Net::SSH.start( @uri.host, @uri.user ) do|ssh| ssh.scp.upload!( source, @uri.path, :recursive => true ) end end |