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 = []) ⇒ Object
-
#initialize(options = {}) ⇒ SSH
constructor
A new instance of SSH.
- #options ⇒ Object
- #put_directory(local_path, remote_path, exclude = []) ⇒ Object
- #put_file(file_path, remote_path) ⇒ Object
Methods inherited from Adapter
Constructor Details
#initialize(options = {}) ⇒ SSH
Returns a new instance of SSH.
6 7 8 9 10 |
# File 'lib/photocopier/ssh.rb', line 6 def initialize( = {}) = = .delete(:gateway) = .delete(:rsync_options) end |
Instance Attribute Details
#gateway_options ⇒ Object (readonly)
Returns the value of attribute gateway_options.
4 5 6 |
# File 'lib/photocopier/ssh.rb', line 4 def end |
#rsync_options ⇒ Object (readonly)
Returns the value of attribute rsync_options.
4 5 6 |
# File 'lib/photocopier/ssh.rb', line 4 def end |
Instance Method Details
#delete(remote_path) ⇒ Object
24 25 26 |
# File 'lib/photocopier/ssh.rb', line 24 def delete(remote_path) exec!("rm -rf #{Shellwords.escape(remote_path)}") end |
#exec!(cmd) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/photocopier/ssh.rb', line 39 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
16 17 18 |
# File 'lib/photocopier/ssh.rb', line 16 def get(remote_path, file_path = nil) session.scp.download! remote_path, file_path end |
#get_directory(remote_path, local_path, exclude = []) ⇒ Object
28 29 30 31 32 |
# File 'lib/photocopier/ssh.rb', line 28 def get_directory(remote_path, local_path, exclude = []) FileUtils.mkdir_p(local_path) remote_path << "/" unless remote_path.end_with?("/") rsync ":#{remote_path}", local_path, exclude end |
#options ⇒ Object
12 13 14 |
# File 'lib/photocopier/ssh.rb', line 12 def .clone end |
#put_directory(local_path, remote_path, exclude = []) ⇒ Object
34 35 36 37 |
# File 'lib/photocopier/ssh.rb', line 34 def put_directory(local_path, remote_path, exclude = []) local_path << "/" unless local_path.end_with?("/") rsync "#{local_path}", ":#{remote_path}", exclude end |
#put_file(file_path, remote_path) ⇒ Object
20 21 22 |
# File 'lib/photocopier/ssh.rb', line 20 def put_file(file_path, remote_path) session.scp.upload! file_path, remote_path end |