Class: Synqa::InternalSshScp
- Inherits:
-
BaseSshScp
- Object
- BaseSshScp
- Synqa::InternalSshScp
- Defined in:
- lib/synqa.rb
Overview
SSH/SCP using Ruby Net::SSH & Net::SCP
Instance Attribute Summary
Attributes inherited from BaseSshScp
Instance Method Summary collapse
- #close ⇒ Object
- #connection ⇒ Object
-
#copyLocalFileToRemoteDirectory(sourcePath, destinationPath, dryRun) ⇒ Object
copy a local file to a remote directory (if dryRun is false).
-
#copyLocalToRemoteDirectory(sourcePath, destinationPath, dryRun) ⇒ Object
copy a local directory to a remote directory (if dryRun is false).
-
#initialize ⇒ InternalSshScp
constructor
A new instance of InternalSshScp.
- #scpConnection ⇒ Object
-
#ssh(commandString, dryRun) ⇒ Object
execute command on remote host (if dryRun is false), yielding lines of output.
Methods inherited from BaseSshScp
#deleteDirectory, #deleteFile, #setUserAtHost
Constructor Details
#initialize ⇒ InternalSshScp
Returns a new instance of InternalSshScp.
224 225 226 |
# File 'lib/synqa.rb', line 224 def initialize @connection = nil end |
Instance Method Details
#close ⇒ Object
240 241 242 243 244 245 246 |
# 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 ⇒ Object
228 229 230 231 232 233 234 |
# 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) ⇒ Object
copy a local file to a remote directory (if dryRun is false)
272 273 274 275 276 277 278 |
# 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) ⇒ Object
copy a local directory to a remote directory (if dryRun is false)
263 264 265 266 267 268 269 |
# 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 ⇒ Object
236 237 238 |
# File 'lib/synqa.rb', line 236 def scpConnection return connection.scp end |
#ssh(commandString, dryRun) ⇒ Object
execute command on remote host (if dryRun is false), yielding lines of output
249 250 251 252 253 254 255 256 257 258 259 260 |
# 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 |