Skip to content

SFTP Activities

Version: 1.1.0  ·  ID: zoan-packages-sftp  ·  Author: Zoan Software

The SFTP package transfers files securely with a remote server through the SFTP protocol (SSH File Transfer Protocol). It is widely used in business-to-business integrations: uploading files to a server (a batch of invoices for a vendor), downloading files left there (bank reports), or managing remote folders. It needs no client installed on the robot’s machine, so it also works in unattended execution.

All operations work on a session that you open with SFTP Connect and share with the other activities. A single connection serves every transfer, without signing in again for each file:

  • With body: the activities inside inherit the session; at the end (also if something fails) the connection closes by itself.
  • Without body: you store the session in a variable, pass it as session and close it with SFTP Close.

Unlike the mail packages, here the session is mandatory: an SFTP activity outside the Connect body and without session fails with 'session' must be a ZoanSftpSession.

SFTP Connect host = "sftp.vendor.com" username = "zoan" password = credential("sftp-vendor")["password"]
└─ body:
SFTP Upload localPath = localFile remotePath = "/inbound/invoice.xml"

SFTP supports two ways to authenticate (choose one in SFTP Connect):

MethodHow
Passwordpassword parameter with a credential — credential("sftp-vendor")["password"].
Private keyprivateKeyPath parameter with the path to your key (.pem / OpenSSH) on the robot’s machine, plus privateKeyPassphrase if it is encrypted. When privateKeyPath is set, the key is used and password is ignored.

The fingerprint (host key) identifies the server. Set it in the hostKeyFingerprint parameter of SFTP Connect and the robot only connects to that server: if another one impersonates it (a man in the middle), the connection is refused before the username or password are sent. Since version 1.1.0.

  • How to get it: connect once without a fingerprint; the log shows a warning with the received fingerprint (SHA256:…), copy it into the parameter. The server administrator can also give it to you (ssh-keygen -lf on the server’s public key).
  • Without a fingerprint: whatever server answers is accepted, as in earlier versions, and its fingerprint is written to the log.
  • If the server changes its key legitimately, the connection fails with an error showing the expected and the received fingerprint: update the parameter.

Server paths use forward slashes /: /inbound/data.csv, /outbound/reports/. A path without a leading / is relative to the user’s home folder on the server. Do not confuse them with local paths (on the robot’s machine), which go in localPath.

ActivityTypeOutputWhat it does
SFTP Connectsftp-connectZoanSftpSessionConnects to the SFTP server
SFTP Closesftp-close—Closes the connection
ActivityTypeOutputWhat it does
SFTP Uploadsftp-uploadstringUploads a local file to the server
SFTP Downloadsftp-downloadstringDownloads a file from the server
ActivityTypeOutputWhat it does
SFTP List Directorysftp-listList<object>Lists remote files and folders
SFTP Existssftp-existsboolDoes a file/folder exist?
SFTP Move / Renamesftp-movestringMoves or renames a remote file
SFTP Deletesftp-delete—Deletes a remote file
SFTP Create Directorysftp-mkdir—Creates a remote folder