wso2 / ballerina-integrator

A powerful, simple-to-learn, code-driven approach to programming integrations
https://wso2.com/integration/ballerina-integrator
Apache License 2.0
70 stars 31 forks source link

[FTP Connector]It only outputs the file size when getting the file size but not the unit. #737

Open isuruuy429 opened 4 years ago

isuruuy429 commented 4 years ago

Description: $subject.

Steps to Reproduce

  1. Create a new Ballerina Project.
  2. Connect to the FTP server and upload employees.xml file to the /home/ftp-user/in location.
  3. Have the following code.
import wso2/ftp;
import ballerina/config;
import ballerina/http;
import ballerina/log;

ftp:ClientEndpointConfig ftpConfig = {
    protocol: ftp:FTP,
    host: config:getAsString("ftp.host"),
    port: config:getAsInt("ftp.port"),
    secureSocket: {
        basicAuth: {
            username: config:getAsString("ftp.username"),
            password: config:getAsString("ftp.password")
        }
    }
};
ftp:Client ftp = new(ftpConfig);

@http:ServiceConfig {
    basePath: "company"
}

 resource function retreiveFileSize(http:Caller caller, http:Request request) returns error? {
        http:Response response = new();
        var sizeResponse = ftp->size("/home/ftp-user/in/employees.xml");
        if (sizeResponse is int) {
            response.setJsonPayload("File size: " +sizeResponse.toString());
            log:printInfo("File size: " + sizeResponse.toString());
    } else {
        response.setJsonPayload({Message: "Error occured in retrieving size", Reason: sizeResponse.reason()});
        log:printError("Error occured in retrieving size", sizeResponse);
    }
    var httpResult = caller->respond(response); 

    }
}
  1. Build the module, run the jar and invoke the service. curl http://localhost:9090/company/retreiveFileSize

It only outputs the size of the file, but not the unit.

Affected Product Version: Ballerina Integrator 7.0.1 Ballerina version: 1.0.2