class Synqa::InternalSshScp
SSH/SCP using Ruby Net::SSH & Net::SCP
Public Class Methods
new()
click to toggle source
# File lib/synqa.rb, line 224 def initialize @connection = nil end
Public Instance Methods
close()
click to toggle source
# File lib/synqa.rb, line 240 def close() if @connection != nil puts "Closing SSH connection to #{user}@#{host} ..." @connection.close() @connection = nil end end
connection()
click to toggle source
# File lib/synqa.rb, line 228 def connection if @connection == nil puts "Opening SSH connection to #{user}@#{host} ..." @connection = Net::SSH.start(host, user) end return @connection end
copyLocalFileToRemoteDirectory(sourcePath, destinationPath, dryRun)
click to toggle source
copy a local file to a remote directory (if dryRun is false)
# File lib/synqa.rb, line 272 def copyLocalFileToRemoteDirectory(sourcePath, destinationPath, dryRun) description = "SCP: copy file #{sourcePath} to #{user}@#{host}:#{destinationPath}" puts description if not dryRun scpConnection.upload!(sourcePath, destinationPath) end end
copyLocalToRemoteDirectory(sourcePath, destinationPath, dryRun)
click to toggle source
copy a local directory to a remote directory (if dryRun is false)
# File lib/synqa.rb, line 263 def copyLocalToRemoteDirectory(sourcePath, destinationPath, dryRun) description = "SCP: copy directory #{sourcePath} to #{user}@#{host}:#{destinationPath}" puts description if not dryRun scpConnection.upload!(sourcePath, destinationPath, :recursive => true) end end
scpConnection()
click to toggle source
# File lib/synqa.rb, line 236 def scpConnection return connection.scp end
ssh(commandString, dryRun) { |line| ... }
click to toggle source
execute command on remote host (if dryRun is false), yielding lines of output
# File lib/synqa.rb, line 249 def ssh(commandString, dryRun) description = "SSH #{user}@#{host}: executing #{commandString}" puts description if not dryRun outputText = connection.exec!(commandString) if outputText != nil then for line in outputText.split("\n") do yield line end end end end