Skip to content

SFTP Download

Type: sftp-download  ·  Package: SFTP Activities v1.1.0  ·  Output: string

Downloads a file from the SFTP server to the robot’s machine. To collect files an external system leaves on the server: bank reports, vendor data, exchange files.

Copies the file at remotePath (server) to localPath (robot’s machine, including the name) and returns the local path:

  • Missing local folders are created.
  • If the local file already exists, it is replaced completely by the downloaded one. Since version 1.1.0 (before, if the previous file was larger, its trailing bytes remained).
  • The download is first written to a temporary file in the same folder and renamed when it finishes: if it fails (for example, the remote file does not exist), the file that was at localPath stays intact and no partial file is left.
  • The remote file is not modified: to archive it use SFTP Move / Rename.
ParameterTypeDefaultDescription
remotePathstring—Path of the remote file to download.
localPathstring—Local destination path, with the file name.
ParameterTypeDefaultDescription
sessionZoanSftpSession—Session from SFTP Connect. Inherited inside a body.

Returns a string with the local path of the downloaded file (the same value as localPath).

MessageCause and fix
'remotePath' is required. / 'localPath' is required.The parameter is missing or the expression returned null.
'session' must be a ZoanSftpSession.The activity is outside the SFTP Connect body and received no session.
Server error: file not foundremotePath does not exist. Check it first with SFTP Exists or take paths from SFTP List Directory.
Local path access errorThe robot cannot write to localPath, or the file is open in another program.

Download all CSV files of a remote folder and archive them on the server:

SFTP Connect host = "sftp.vendor.com" username = "zoan" password = credential("sftp-vendor")["password"]
└─ body:
SFTP List Directory remotePath = "/outbound" pattern = "*.csv" → output: files
For Each items = files itemVariable = item
└─ activities:
SFTP Download remotePath = item["fullName"] localPath = pathJoin("C:/downloads", item["name"]) → output: localFile
Read CSV path = localFile → output: data
SFTP Move / Rename sourcePath = item["fullName"] destinationPath = "/outbound/processed/" + item["name"]