The WSO2 FTP Connector enables you to connect to an FTP server and perform operations on files and folders stored on the server. FTP connector offers FTP Client, which supports the generic FTP operations such as
list, as well as an FTP listener that listens to the remote FTP server and triggers events.
- FTP Client
- FTP Listener
Let’s look into how we can use these FTP operations in the FTP Client.
- Download and install Ballerina Integrator for your operating system.
- Install Oracle JDK 1.8.*
- Install VS Code
- Install the Ballerina Integrator Extension from the VS Code marketplace
- Setup an FTP server.
- Make sure you have uploaded an employees.xml file to the ftp location /home/ftp-server/in since we are going to read the file through this folder.
It has been already given a sample at WSO2 docs on writing a file to an FTP server. You can find it here.
Let us focus on the rest of the scenarios.
Reading a file from the remote FTP server.
First, it needs to configure the FTP Client as below where we should provide the FTP server credentials in the ballerina.conf file which is created in the project root directory.
For creating a ballerina project from scratch please refer https://ei.docs.wso2.com/en/next/ballerina-integrator/get-started/quick-start-guide/
My base path will be configured as company.
The resource configuration looks like below.
We need to import the following.
The complete source will look as below.
We can simply build the module by running by the following command which will build all the modules. A jar will be created in the target folder.
ballerina build -a
Run the jar as below and the service will be started in the port 9090.
java -jar <jar name>
Invoke the resource as below.
It will output the content of the file.
Deleting a file from the remote FTP server.
Creating a folder in the remote FTP server.
Remove a folder in the remote FTP server.
Rename a file in the remote FTP server.
Retrieve a file size of a file in the remote FTP server.
To read about the FTP listener operations you can refer here.