SFTP task
Table of Contents
Note: Each SFTP task execution triggers an API call in the back-end. These API calls are deducted from your overall external calls limit that is provided for your Creator plan. Here, the system counts the number of actual executions, and not the number of times the task appears in the script.
Overview
The SSH File Transfer Protocol (SFTP) task in Deluge allows you to access and modify:
- files on a remote server using upload and download operations.
- file transfers between your Zoho service and external storage.
Note:
- You can use this task to download files up to 5 MB.
- This task is currently not applicable in Zoho Flow.
Syntax
response = SFTP [ action: action_type host: host_name port: port_number path: path_value files: file_name connection: connection_name ];
| Parameter | Data type | Description |
|---|---|---|
| <response> | KEY-VALUE / FILE / TEXT / LIST | The variable that will contain the response returned. Specify if the response is to be performed on the remote server. |
| <action_type> | TEXT | The type of action to be performed in the server.
|
| <host_name> | TEXT | The domain name of the remote server. |
| <port_number> | (Optional) NUMBER | The value of the port of the server to be mentioned. Default: 22 |
| <path_value> | TEXT | The URL path of the service to be accessed, excluding the base URL. For example, "/myftpserver.example.com". The path is necessary, especially for download action.If no path is specified, the root directory will be considered as the destination folder. If a path is specified, then it must start with "/" . |
| <file_object> | (Optional) TEXT | The name of the file object to be uploaded to the server. This is mandatory for upload. |
| <connection_name> | (Optional) TEXT | The connection name configured to access the remote server. |
Use Case
An enterprise manages updated policy documents and procedural templates that are sourced from a public repository. These documents need to be uploaded to a secure SFTP server so internal teams and automated systems can access the latest files from a centralized, trusted location.
// Log initial step info "SFTP"; info "****"; // Download a sample file from a public URL sftpTxtFile = invokeurl [ url : "https://sample-files.com/downloads/documents/txt/simple.txt" type : GET ]; // Convert the text response into a file object sftpTxtFile = sftpTxtFile.toFile("sftp.txt"); info sftpTxtFile; // Upload the file to a secure SFTP server uploadFtp = sftp [ action : upload host : "sftp.examplehost.com" port : 22 path : "" files : sftpTxtFile connection : "sftp_connection" ]; info uploadFtp; // Download the same file from the SFTP server downloadFtp = sftp [ action : download host : "sftp.examplehost.com" port : 22 path : "/sftp.txt" connection : "sftp_connection" ]; info downloadFtp; // Output the content of the downloaded file for validation info downloadFtp.getFileContent();
Examples
Example 1: Upload File to a Remote Server
// Upload a file to SFTP server uploadSftp = sftp [ action : upload host : "sftp.examplehost.com" port : 22 path : "/exports/" files : monthlyreport connection : "sftp_connection" ]; info uploadSftp;
Example 2: Download File from a Remote Server
// Download a file from SFTP server downloadSftp = sftp [ action : download host : "ftp.examplehost.com" port : 22 path : "/home/uploads/example.png" ]; info downloadSftp;
Response Format
The standard response will be returned in the following format:
{
"responseText": "Example.png",
}
- The response for the request to return the response code will be in the following format:
{
File has been uploaded successfully
200
}
File has been uploaded successfully
200
}