Class: Synqa::InternalSshScp

Inherits:
BaseSshScp show all
Defined in:
lib/synqa.rb

Overview

SSH/SCP using Ruby Net::SSH & Net::SCP

Instance Method Summary collapse

Methods inherited from BaseSshScp

#deleteDirectory, #deleteFile

Instance Method Details

#copyLocalFileToRemoteDirectory(userAtHost, sourcePath, destinationPath, dryRun) ⇒ Object

copy a local file to a remote directory (if dryRun is false)



241
242
243
244
245
246
247
248
# File 'lib/synqa.rb', line 241

def copyLocalFileToRemoteDirectory(userAtHost, sourcePath, destinationPath, dryRun)
  user, host = userAtHost.split("@")
  description = "SCP: copy file #{sourcePath} to #{user}@#{host}:#{destinationPath}"
  puts description
  if not dryRun
    Net::SCP.upload!(host, user, sourcePath, destinationPath)
  end
end

#copyLocalToRemoteDirectory(userAtHost, sourcePath, destinationPath, dryRun) ⇒ Object

copy a local directory to a remote directory (if dryRun is false)



231
232
233
234
235
236
237
238
# File 'lib/synqa.rb', line 231

def copyLocalToRemoteDirectory(userAtHost, sourcePath, destinationPath, dryRun)
  user, host = userAtHost.split("@")
  description = "SCP: copy directory #{sourcePath} to #{user}@#{host}:#{destinationPath}"
  puts description
  if not dryRun
    Net::SCP.upload!(host, user, sourcePath, destinationPath, :recursive => true)
  end
end

#ssh(userAtHost, commandString, dryRun) ⇒ Object

execute command on remote host (if dryRun is false), yielding lines of output



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/synqa.rb', line 214

def ssh(userAtHost, commandString, dryRun)
  user, host = userAtHost.split("@")
  description = "SSH #{user}@#{host}: executing #{commandString}"
  puts description
  if not dryRun
    Net::SSH.start(host, user) do |ssh|
      outputText = ssh.exec!(commandString)
      if outputText != nil then
        for line in outputText.split("\n") do
          yield line
        end
      end
    end
  end
end