Module ftp
API
Declarations

ballerina/ftp Ballerina library
Clients
ftp: Caller
Represents an FTP caller that is passed to the onFileChange function
get
Retrieves the file content from a remote resource.
stream<byte[] & readonly, io:Error?>|ftp:Error channel = caller->get(path);
Parameters
- path string - The resource path
Return Type
append
function append(string path, stream<byte[] & readonly, Error?>|string|xml|json content) returns Error?
Appends the content to an existing file in an FTP server.
ftp:Error? response = caller->append(path, channel);
Parameters
- path string - The resource path
Return Type
- Error? -
()
or else anftp:Error
if failed to establish the communication with the FTP server
put
function put(string path, stream<byte[] & readonly, Error?>|string|xml|json content, Compression compressionType) returns Error?
Adds a file to an FTP server.
ftp:Error? response = caller->put(path, channel);
Parameters
- path string - The resource path
- compressionType Compression (default NONE) - Type of the compression to be used, if the file should be compressed before uploading
Return Type
- Error? -
()
or else anftp:Error
if failed to establish the communication with the FTP server
mkdir
Creates a new directory in an FTP server.
ftp:Error? response = caller->mkdir(path);
Parameters
- path string - The directory path
Return Type
- Error? -
()
or else anftp:Error
if failed to establish the communication with the FTP server
rmdir
Deletes an empty directory in an FTP server.
ftp:Error? response = caller->rmdir(path);
Parameters
- path string - The directory path
Return Type
- Error? -
()
or else anftp:Error
if failed to establish the communication with the FTP server
rename
Renames a file or moves it to a new location within the same FTP server.
ftp:Error? response = caller->rename(origin, destination);
Parameters
- origin string - The source file location
- destination string - The destination file location
Return Type
- Error? -
()
or else anftp:Error
if failed to establish the communication with the FTP server
size
Gets the size of a file resource.
int|ftp:Error response = caller->size(path);
Parameters
- path string - The resource path
Return Type
list
Gets the file name list in a given folder.
ftp:FileInfo[]|ftp:Error response = caller->list(path);
Parameters
- path string - The directory path
Return Type
isDirectory
Checks if a given resource is a directory.
boolean|ftp:Error response = caller->isDirectory(path);
Parameters
- path string - The resource path
Return Type
delete
Deletes a file from an FTP server.
ftp:Error? response = caller->delete(path);
Parameters
- path string - The resource path
Return Type
- Error? -
()
or else anftp:Error
if failed to establish the communication with the FTP server
ftp: Client
Represents an FTP client that intracts with an FTP server
Constructor
Gets invoked during object initialization.
init (ClientConfiguration clientConfig)
- clientConfig ClientConfiguration - Configurations for FTP client
get
Retrieves the file content from a remote resource.
stream<byte[] & readonly, io:Error?>|ftp:Error channel = client->get(path);
Parameters
- path string - The resource path
Return Type
append
function append(string path, stream<byte[] & readonly, Error?>|string|xml|json content) returns Error?
Appends the content to an existing file in an FTP server.
ftp:Error? response = client->append(path, channel);
Parameters
- path string - The resource path
Return Type
- Error? -
()
or else anftp:Error
if failed to establish the communication with the FTP server
put
function put(string path, stream<byte[] & readonly, Error?>|string|xml|json content, Compression compressionType) returns Error?
Adds a file to an FTP server.
ftp:Error? response = client->put(path, channel);
Parameters
- path string - The resource path
- compressionType Compression (default NONE) - Type of the compression to be used, if the file should be compressed before uploading
Return Type
- Error? -
()
or else anftp:Error
if failed to establish the communication with the FTP server
mkdir
Creates a new directory in an FTP server.
ftp:Error? response = client->mkdir(path);
Parameters
- path string - The directory path
Return Type
- Error? -
()
or else anftp:Error
if failed to establish the communication with the FTP server
rmdir
Deletes an empty directory in an FTP server.
ftp:Error? response = client->rmdir(path);
Parameters
- path string - The directory path
Return Type
- Error? -
()
or else anftp:Error
if failed to establish the communication with the FTP server
rename
Renames a file or moves it to a new location within the same FTP server.
ftp:Error? response = client->rename(origin, destination);
Parameters
- origin string - The source file location
- destination string - The destination file location
Return Type
- Error? -
()
or else anftp:Error
if failed to establish the communication with the FTP server
size
Gets the size of a file resource.
int|ftp:Error response = client->size(path);
Parameters
- path string - The resource path
Return Type
list
Gets the file name list in a given folder.
ftp:FileInfo[]|ftp:Error response = client->list(path);
Parameters
- path string - The directory path
Return Type
isDirectory
Checks if a given resource is a directory.
boolean|ftp:Error response = client->isDirectory(path);
Parameters
- path string - The resource path
Return Type
delete
Deletes a file from an FTP server.
ftp:Error? response = client->delete(path);
Parameters
- path string - The resource path
Return Type
- Error? -
()
or else anftp:Error
if failed to establish the communication with the FTP server
Service types
ftp: Service
Represents a FTP service.
Enums
ftp: Compression
Compression type.
Members
ftp: PreferredMethod
Authentication methods for the FTP listener.
Members
ftp: Protocol
Represents the set of protocols supported by the FTP listener and client.
Members
Listeners
ftp: Listener
Represents a service listener that monitors the FTP location.
Constructor
Gets invoked during object initialization.
init (*ListenerConfiguration listenerConfig)
- listenerConfig *ListenerConfiguration - Configurations for FTP listener
attach
Binds a service to the ftp:Listener
.
error? response = listener.attach(service1);
Parameters
- ftpService Service - Service to be detached from the listener
Return Type
- error? -
()
or else anerror
upon failure to register the listener
'start
function 'start() returns error?
Starts the ftp:Listener
.
error? response = listener.'start();
Return Type
- error? -
()
or else anerror
upon failure to start the listener
detach
Stops consuming messages and detaches the service from the ftp:Listener
.
error? response = listener.detach(service1);
Parameters
- ftpService Service - Service to be detached from the listener
Return Type
- error? -
()
or else anerror
upon failure to detach the service
immediateStop
function immediateStop() returns error?
Stops the ftp:Listener
forcefully.
error? response = listener.immediateStop();
Return Type
- error? -
()
or else anerror
upon failure to stop the listener
gracefulStop
function gracefulStop() returns error?
Stops the ftp:Listener
gracefully.
error? response = listener.gracefulStop();
Return Type
- error? -
()
or else anerror
upon failure to stop the listener
poll
function poll() returns error?
Poll new files from a FTP server.
error? response = listener.poll();
Return Type
- error? - An
error
if failed to establish communication with the FTP server
register
Register a FTP service in an FTP listener server.
error? response = listener.register(ftpService, name);
Return Type
- error? - An
error
if failed to establish communication with the FTP server
Records
ftp: AuthConfiguration
Configurations for facilitating secure communication with a remote FTP server.
Fields
- credentials? Credentials - Username and password to be used
- privateKey? PrivateKey - Private key to be used
- preferredMethods PreferredMethod[](default [PUBLICKEY, PASSWORD]) - Preferred authentication methods
ftp: ClientConfiguration
Configuration for FTP client.
Fields
- protocol Protocol(default FTP) - Supported FTP protocols
- host string(default "127.0.0.1") - Target service URL
- port int(default 21) - Port number of the remote service
- auth? AuthConfiguration - Authentication options
ftp: Credentials
Username/password authentication related configurations.
Fields
- username string - Username of the user
- password string - Password of the user
ftp: FileInfo
Metadata for newly-added files.
Fields
- path string - Relative file path for a newly-added file
- size int - Size of the file
- lastModifiedTimestamp int - Last-modified timestamp of the file in UNIX Epoch time
- name string - File name
- isFolder boolean -
true
if the file is a folder
- isFile boolean -
true
if the file is a file
- pathDecoded string - Normalized absolute path of this file within its file system
- extension string - Extension of the file name
- publicURIString string - Receiver as a URI String for public display
- fileType string - Type of the file
- isAttached boolean -
true
if thefileObject
is attached
- isContentOpen boolean -
true
if someone reads/writes from/to this file
- isExecutable boolean -
true
if this file is executable
- isHidden boolean -
true
if this file is hidden
- isReadable boolean -
true
if this file can be read
- isWritable boolean -
true
if this file can be written
- depth int - Depth of the file name within its file system
- scheme string - URI scheme of the file
- uri string - Absolute URI of the file
- rootURI string - Root URI of the file system in which the file exists
- friendlyURI string - A "friendly path" is a path, which can be accessed without a password
ftp: InputContent
Configuration for the input given for put
and append
operations of
the FTP module.
Fields
- filePath string - Path of the file to be created or appended
- isFile boolean(default false) -
true
if the input type is a file
- textContent? string - The input content, for other input types
- compressInput boolean(default false) - If true, input will be compressed before uploading
ftp: ListenerConfiguration
Configuration for FTP listener.
Fields
- protocol Protocol(default FTP) - Supported FTP protocols
- host string(default "127.0.0.1") - Target service url
- port int(default 21) - Port number of the remote service
- auth? AuthConfiguration - Authentication options
- path string(default "/") - Remote FTP directory location
- fileNamePattern? string - File name pattern that event need to trigger
- pollingInterval decimal(default 60) - Periodic time interval to check new update
ftp: PrivateKey
Configuration to read a privte key.
Fields
- path string - Path to the private key file
- password? string - Private key password
ftp: WatchEvent
This represents the latest status change of the server from the last status change.
Fields
- addedFiles FileInfo[] - Array of
ftp:FileInfo
that represents newly added files
- deletedFiles string[] - Array of strings that contains deleted file names
Errors
ftp: Error
Defines the common error type for the module.
Import
import ballerina/ftp;
Metadata
Released date: 8 days ago
Version: 2.12.0
License: Apache-2.0
Compatibility
Platform: java21
Ballerina version: 2201.11.0
GraalVM compatible: Yes
Pull count
Total: 3423
Current verison: 0
Weekly downloads
Keywords
FTP
SFTP
remote file
file transfer
client
service
Contributors