SFTP Functions: sftphandler
The SFTP functions enable automation workflows to interact with an SFTP (Secure File Transfer Protocol) server. They support operations such as creating a connection, downloading and uploading files, monitoring directories, creating directories, and closing the connection.
Prerequisites:
- SFTP Server Credentials: Ensure you have the server IP, port, username, and password.
Available Commands:
- Create Connection (createConnection): Establishes a connection to the SFTP server.
- Download (download): Retrieves files from the SFTP server to a local directory.
- Upload (upload): Sends files from a local directory to the SFTP server.
- Watch (watch): Monitors a specified directory on the SFTP server for files with a particular extension.
- Create Directory (createDirectory): Creates a new directory on the SFTP server.
- Close Connection (closeConnection): Terminates the connection to the SFTP server.
Steps to Configure Each Command:
- Create Connection (createConnection)
Establish a connection to the SFTP server.
- Action: Select Set a Variable Value from the Action dropdown.
- Element Key: Enter a variable name to store the connection status (e.g., SFTPConnectionStatus).
- Parameters:
- Cmd: Select createConnection.
- ServerIP: Enter the SFTP server’s IP address (e.g., 123.456.7.89).
- Port: Enter the port number (default is 22).
- UserName: Enter your SFTP username (e.g., sftp_user).
- Password: Enter your SFTP password (e.g., P@ssword123).


- Outcome: Returns true if the connection is successful; otherwise, returns false.
- Download (download)
Download files from the SFTP server.
- Action: Select Set a Variable Value from the Action
dropdown. - Element Key: Enter a variable name to store the download status (e.g., DownloadStatus).
- Parameters:
- Cmd: Select download.
- destination: Specify the path of the file on the SFTP server (e.g.,
/remote/folder/file.txt). - source: Specify the local directory path where the file will be saved (e.g.,
C:LocalFolderfile.txt).
- Action: Select Set a Variable Value from the Action


- Outcome: Returns true if the download is successful; otherwise, returns
false.
- Outcome: Returns true if the download is successful; otherwise, returns
- Upload (upload)
Upload files to the SFTP server.
- Action: Select Set a Variable Value from the Action
dropdown. - Element Key: Enter a variable name to store the upload status (e.g., UploadStatus).
- Parameters:
- Cmd: Select upload.
- destination: Specify the destination path on the SFTP server (e.g.,
/remote/folder/uploaded_file.txt). - source: Specify the local file path to be uploaded (e.g., C:LocalFolderfile.txt).
- Action: Select Set a Variable Value from the Action


- Outcome: Returns true if the upload is successful; otherwise, returns
false.
- Outcome: Returns true if the upload is successful; otherwise, returns
- Watch (watch):
Monitor a directory on the SFTP server for files with a specific extension.
- Action: Select Set a Variable Value from the Action dropdown.
dropdown. - Element Key: Enter a variable name to store the path of the detected file (e.g.,
WatchedFilePath). - Parameters:
- Cmd: Select watch.
- remotePath: Specify the directory path on the SFTP server to monitor (e.g.,
/remote/logs/). - extension: Specify the file extension to watch for (e.g., .txt).
- prefix: (Optional) Specify a filename prefix to filter.
- timeout: (Optional) Set the duration (in seconds) to wait for a file to appear.
- orderBy: (Optional) Specify the order criterion (e.g., dateTime).
- sortBy: (Optional) Specify the sort order (asc for ascending, desc for descending).
- Action: Select Set a Variable Value from the Action dropdown.


- Outcome: Returns the path of the detected file if found within the timeout period; otherwise,
returns null.
- Outcome: Returns the path of the detected file if found within the timeout period; otherwise,
- Create Directory (createDirectory)
Create a new directory on the SFTP server.
- Action: Select Set a Variable Value from the Action
dropdown. - Element Key: Enter a variable name to store the operation status (e.g.,
DirectoryCreationStatus). - Parameters:
- Cmd: Select createDirectory.
- directoryPath: Specify the path of the new directory to be created on the SFTP server
(e.g., /remote/new_folder/).
- Action: Select Set a Variable Value from the Action


- Outcome: Returns true if the directory is successfully created; otherwise,
returns false.
- Outcome: Returns true if the directory is successfully created; otherwise,
- Close Connection (closeConnection)
Terminate the connection to the SFTP server.
- Action: Select Set a Variable Value from the Action
dropdown. - Element Key: Enter a variable name to store the disconnection status (e.g.,
DisconnectionStatus). - Parameters:
- Cmd: Select closeConnection.
- Action: Select Set a Variable Value from the Action


- Outcome: Returns true if the connection is successfully closed; otherwise,
returns false.
- Outcome: Returns true if the connection is successfully closed; otherwise,