Class: Synqa::ExternalSshScp

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

Overview

SSH/SCP using external commands, such as “plink” and “pscp”

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseSshScp

#deleteDirectory, #deleteFile

Constructor Details

#initialize(shell, scpProgram) ⇒ ExternalSshScp

Returns a new instance of ExternalSshScp.



263
264
265
266
267
# File 'lib/synqa.rb', line 263

def initialize(shell, scpProgram)
  @shell = shell.is_a?(String) ? [shell] : shell
  @scpProgram = scpProgram.is_a?(String) ? [scpProgram] : scpProgram
  @scpCommandString = @scpProgram.join(" ")
end

Instance Attribute Details

#scpCommandStringObject (readonly)

The SCP command as a string



261
262
263
# File 'lib/synqa.rb', line 261

def scpCommandString
  @scpCommandString
end

#scpProgramObject (readonly)

The SCP client, e.g. [“scp”] or [“pscp”,“-pw”,“mysecretpassword”] (i.e. command + args as an array)



258
259
260
# File 'lib/synqa.rb', line 258

def scpProgram
  @scpProgram
end

#shellObject (readonly)

The SSH client, e.g. [“ssh”] or [“plink”,“-pw”,“mysecretpassword”] (i.e. command + args as an array)



255
256
257
# File 'lib/synqa.rb', line 255

def shell
  @shell
end

Instance Method Details

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

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



288
289
290
# File 'lib/synqa.rb', line 288

def copyLocalFileToRemoteDirectory(userAtHost, sourcePath, destinationPath, dryRun)
  executeCommand("#{@scpCommandString} #{sourcePath} #{userAtHost}:#{destinationPath}", dryRun)
end

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

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



283
284
285
# File 'lib/synqa.rb', line 283

def copyLocalToRemoteDirectory(userAtHost, sourcePath, destinationPath, dryRun)
  executeCommand("#{@scpCommandString} -r #{sourcePath} #{userAtHost}:#{destinationPath}", dryRun)
end

#ssh(userAtHost, commandString, dryRun) ⇒ Object

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



270
271
272
273
274
275
276
277
278
279
280
# File 'lib/synqa.rb', line 270

def ssh(userAtHost, commandString, dryRun)
  puts "SSH #{userAtHost} (#{shell.join(" ")}): executing #{commandString}"
  if not dryRun
    output = getCommandOutput(shell + [userAtHost, commandString])
    while (line = output.gets)
      yield line.chomp
    end
    output.close()
    checkProcessStatus("SSH #{userAtHost} #{commandString}")
  end
end