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
- Open the workspace editor
- In the Operation catalogue filter the operations list for operations containing the phrase "Ssh"
- Drag the operation entitled "SshLogin" onto the workspace canvas and select it
- Update the Host property with the host name of the server to which you want to connect over SSH
- Update the User name property with the user name you want to connect with
- 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)
- Enter the port to connect to the host on (usually 22 for SSH)
- 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
- 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
- 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
- Next, drag the "SshSendCommand" operation onto your workspace canvas
- Next, connect the SSH Login's Session output to the Session input on the SSH Send Command operation
- 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)
- 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
- Finally, right click on the dependencies output on your LogText operation and choose the Create workspace output menu to generate a workspace output
- 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
- Again, as before, configure your workflow to log into a server over SSH
- Next, drag the SshSendFile operation onto your workspace canvas
- Connect your SSH Login operation's Session output to the Session input of the SshSendFile operation
- Next, set the Source file path input on your SSH Send file operation to the file you want to send to the server
- Set the destination path on the server (including the full filename of the destination file including extension)
- 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.