ballerina/ftp Ballerina library
This module provides an FTP/SFTP client and an FTP/SFTP server listener implementation to facilitate an FTP/SFTP connection connected to a remote location.
ftp:Client connects to an FTP server and performs various operations on the files. Currently, it supports the
generic FTP operations;
An FTP client is defined using the
host parameters and optionally, the
auth. Authentication configuration can be configured using the
auth parameter for Basic Auth and
An authentication-related configuration can be given to the FTP client with the
Creating a Client
The following code creates an FTP client and performs the I/O operations, which connect to the FTP server with Basic Auth.
Creating a Directory
The following code creates a directory in the remote FTP server.
Uploading File to a Remote Server
The following code uploads a file to a remote FTP server.
Compressing and Uploading a File to a Remote Server
The following code compresses and uploads a file to a remote FTP server.
Getting the Size of a Remote File
The following code gets the size of a file in a remote FTP server.
Reading the Content of a Remote File
The following code reads the content of a file in a remote FTP server.
Renaming or Moving a Remote file to Another Remote Location in the Same FTP Server
The following code renames or moves a file to another location in the same remote FTP server.
Deleting a Remote File
The following code deletes a remote file in a remote FTP server.
Removing a Directory From a Remote Server
The following code removes a directory in a remote FTP server.
ftp:Listener is used to listen to a remote FTP location and trigger a
WatchEvent type of event when new
files are added to or deleted from the directory. The
fileResource function is invoked when a new file is added
An FTP listener is defined using the mandatory
path parameters. The authentication
configuration can be done using the
auth parameter and the polling interval can be configured using the
The default polling interval is 60 seconds.
fileNamePattern parameter can be used to define the type of files the FTP listener will listen to.
For instance, if the listener gets invoked for text files, the value
(.*).txt can be given for the config.
An authentication-related configuration can be given to the FTP listener with the
Creating a Listener
The FTP Listener can be used to listen to a remote directory. It will keep listening to the specified directory and notify on file addition and deletion periodically.
Secure access with SFTP
SFTP is a secure protocol alternative to the FTP, which runs on top of the SSH protocol.
There are several ways to authenticate an SFTP server. One is using the username and the password.
Another way is using the client's private key. The Ballerina SFTP client and the listener support only those authentication standards.
An authentication-related configuration can be given to the SFTP client/listener with the
Password-based authentication is defined with the
credentials configuration while the private key based authentication is defined with the
SFTP Client Configuration
SFTP Listener Configuration
Released date: almost 2 years ago
Ballerina version: 2201.0.1
Pull count: 826