Class: Photocopier::SSH
Instance Attribute Summary collapse
-
#gateway_options ⇒ Object
readonly
Returns the value of attribute gateway_options.
-
#rsync_options ⇒ Object
readonly
Returns the value of attribute rsync_options.
Attributes inherited from Adapter
Instance Method Summary collapse
- #delete(remote_path) ⇒ Object
- #exec!(cmd) ⇒ Object
- #get(remote_path, file_path = nil) ⇒ Object
- #get_directory(remote_path, local_path, exclude = [], includes = []) ⇒ Object
-
#initialize(options = {}) ⇒ SSH
constructor
A new instance of SSH.
- #options ⇒ Object
- #put_directory(local_path, remote_path, exclude = [], includes = []) ⇒ Object
- #put_file(file_path, remote_path) ⇒ Object
Methods inherited from Adapter
Constructor Details
#initialize(options = {}) ⇒ SSH
Returns a new instance of SSH.
5 6 7 8 9 |
# File 'lib/photocopier/ssh.rb', line 5 def initialize( = {}) @options = @gateway_options = .delete(:gateway) @rsync_options = .delete(:rsync_options) end |
Instance Attribute Details
#gateway_options ⇒ Object (readonly)
Returns the value of attribute gateway_options.
3 4 5 |
# File 'lib/photocopier/ssh.rb', line 3 def @gateway_options end |
#rsync_options ⇒ Object (readonly)
Returns the value of attribute rsync_options.
3 4 5 |
# File 'lib/photocopier/ssh.rb', line 3 def @rsync_options end |
Instance Method Details
#delete(remote_path) ⇒ Object
23 24 25 |
# File 'lib/photocopier/ssh.rb', line 23 def delete(remote_path) exec!("rm -rf #{Shellwords.escape(remote_path)}") end |
#exec!(cmd) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/photocopier/ssh.rb', line 38 def exec!(cmd) stdout = "" stderr = "" exit_code = nil session.open_channel do |channel| channel.exec(cmd) do |_ch, _success| channel.on_data do |_ch, data| stdout << data end channel.on_extended_data do |_ch, _type, data| stderr << data end channel.on_request("exit-status") do |_ch, data| exit_code = data.read_long end end end session.loop [stdout, stderr, exit_code] end |
#get(remote_path, file_path = nil) ⇒ Object
15 16 17 |
# File 'lib/photocopier/ssh.rb', line 15 def get(remote_path, file_path = nil) session.scp.download! remote_path, file_path end |
#get_directory(remote_path, local_path, exclude = [], includes = []) ⇒ Object
27 28 29 30 31 |
# File 'lib/photocopier/ssh.rb', line 27 def get_directory(remote_path, local_path, exclude = [], includes = []) FileUtils.mkdir_p(local_path) remote_path << "/" unless remote_path.end_with?("/") rsync ":#{remote_path}", local_path, exclude, includes end |
#options ⇒ Object
11 12 13 |
# File 'lib/photocopier/ssh.rb', line 11 def @options.clone end |
#put_directory(local_path, remote_path, exclude = [], includes = []) ⇒ Object
33 34 35 36 |
# File 'lib/photocopier/ssh.rb', line 33 def put_directory(local_path, remote_path, exclude = [], includes = []) local_path << "/" unless local_path.end_with?("/") rsync local_path.to_s, ":#{remote_path}", exclude, includes end |
#put_file(file_path, remote_path) ⇒ Object
19 20 21 |
# File 'lib/photocopier/ssh.rb', line 19 def put_file(file_path, remote_path) session.scp.upload! file_path, remote_path end |