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

Attributes inherited from BaseSshScp

#host, #user, #userAtHost

Instance Method Summary collapse

Methods inherited from BaseSshScp

#close, #deleteDirectory, #deleteFile, #setUserAtHost

Constructor Details

#initialize(shell, scpProgram) ⇒ ExternalSshScp

Returns a new instance of ExternalSshScp.



293
294
295
296
297
# File 'lib/synqa.rb', line 293

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



291
292
293
# File 'lib/synqa.rb', line 291

def scpCommandString
  @scpCommandString
end

#scpProgramObject (readonly)

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



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

def scpProgram
  @scpProgram
end

#shellObject (readonly)

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



285
286
287
# File 'lib/synqa.rb', line 285

def shell
  @shell
end

Instance Method Details

#copyLocalFileToRemoteDirectory(sourcePath, destinationPath, dryRun) ⇒ Object

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



318
319
320
# File 'lib/synqa.rb', line 318

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

#copyLocalToRemoteDirectory(sourcePath, destinationPath, dryRun) ⇒ Object

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



313
314
315
# File 'lib/synqa.rb', line 313

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

#ssh(commandString, dryRun) ⇒ Object

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



300
301
302
303
304
305
306
307
308
309
310
# File 'lib/synqa.rb', line 300

def ssh(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