Workspace 6.21.5
Performing SSH operations in your workflows

Introduction

In this tutorial we will see how to incorporate SSH operations into our workflows including:

  • How to log into a server over SSH
  • How to send a file to a server over an SSH session
  • How to execute an arbitrary command on a server over an SSH session
  • How to copy a file from a server to the local machine over SSH

Contents


How to connect to a server over SSH

  1. Open the workspace editor
  2. In the Operation catalogue filter the operations list for operations containing the phrase "Ssh"
  3. Drag the operation entitled "SshLogin" onto the workspace canvas and select it
  4. Update the Host property with the host name of the server to which you want to connect over SSH
  5. Update the User name property with the user name you want to connect with
  6. Next, update the Private key file property with the private ssh key (the corresponding public key of which exists in your server's key store)
  7. Enter the port to connect to the host on (usually 22 for SSH)
  8. Next, expand your SSH Login's operations master output port and right click on one of the outputs and choose the "Create workspace output" menu item
  9. Finally run your workflow to log into your server over SSH
Connecting to a remote host

How to send a command to a server over SSH and print the result of the command

  1. Continuing on from the above workflow, highlight the workspace output you created and delete it leaving just the SSH Login operation on your workflow canvas
  2. Next, drag the "SshSendCommand" operation onto your workspace canvas
  3. Next, connect the SSH Login's Session output to the Session input on the SSH Send Command operation
  4. Next, enter a command to execute on the server by entering it into the Command input on the SSH Send Command operation i.e. "hostname" (shows the server's host name)
  5. Next, add the LogText operation to your workspace canvas and connect the Result output of the SSH Send Command operation to the Text to log input on the LogText operation
  6. Finally, right click on the dependencies output on your LogText operation and choose the Create workspace output menu to generate a workspace output
  7. Reset the SshLogin operation and run the workflow. You should notice that the workspace log window displays the output of the command we just sent to the server i.e. our server's host name
Sending a command to a remote host

How to send a local file to a server over SSH

  1. Again, as before, configure your workflow to log into a server over SSH
  2. Next, drag the SshSendFile operation onto your workspace canvas
  3. Connect your SSH Login operation's Session output to the Session input of the SshSendFile operation
  4. Next, set the Source file path input on your SSH Send file operation to the file you want to send to the server
  5. Set the destination path on the server (including the full filename of the destination file including extension)
  6. Finally, generate a workspace output for the SSH Send File command and run.
Sending a file to a remote host

How to copy a file from a server to your local machine over SSH

This is the inverse operation of SSH Send File and so simply use the SSH Get File operation in place of the send file operation used in the above tutorial and configure with the target file on the server and destination file on your local machine.

Getting a file from a remote host

Summary

This concludes the tutorial on using the workspace SSH operations.