Skip to content

Ballerina FTP Module 0.99.0 Released!

Compare
Choose a tag to compare
@daneshk daneshk released this 10 Dec 05:15
· 3360 commits to master since this release

This is the latest release that compatible with Ballerina runtime 0.990.0.
FTP functionalities haven't changed this release, but syntax changed to compatible with new Ballerina runtime.

FTP Listener

The FTP Listener can be used to listen to a remote directory. It will keep listening to the specified directory and periodically notify the file addition and deletion.

import wso2/ftp;
import ballerina/log;

listener ftp:Listener remoteServer = new({
    protocol:ftp:FTP,
    host:"localhost",
    port:48123,
    secureSocket: {
        basicAuth: {
            username: "ballerina",
            password: "ballerina123"
        }
    },
    path:"/home/ballerina"
});

service monitor on remoteLocation {
    resource function fileResource (ftp:WatchEvent m) {
        foreach ftp:FileInfo v1 in m.addedFiles {
            log:printInfo("Added file path: " + v1.path);
        }
        
        foreach string v2 in m.deletedFiles {
            log:printInfo("Deleted file path: " + v2);
        }
    }
}

FTP Client

The FTP Client Connector can be used to connect to an FTP server and perform I/O operations.

import wso2/ftp;
import ballerina/io;
    
function main (string... args) {
    ftp:Client ftpClient = new({ protocol: ftp:FTP, host: "127.0.0.1", port: 21 });
    // To create a folder in remote server
    var dirCreErr = ftpClient -> mkdir("/ballerina-user/sample-dir");
    if (dirCreErr is error) {
        io:println("An error occured.");
        return;
    }   
}