ftp - 如何将端点作为参数传递给 Ballerina 中的函数

标签 ftp ftp-client ballerina

我在一些文件传输过程中使用“wso2/ftp”包,并且在我的主 .bal 文件中有一个 ftp:Client 端点,如下所示。

endpoint ftp:Client server1 {
    protocol: ftp:FTP,
    host:<ip_address>,
    port:21,
    secureSocket: {
        basicAuth: {
            username: <user_name>,
            password: <password>
        }
    }
};

将此端点传递给另一个 .bal 文件中的公共(public)函数的方法有哪些。

尝试这样做,

function functionName(ftp:Client server1){
    functionFromOtherBalFile(server1);
} 

但出现错误

invalid action invocation, expected an endpoint

来自包含“functionFromOtherBalFile”实现的第二个 .bal 文件。

“functionFromOtherBalFile”的实现:

public function functionFromOtherBalFile(ftp:Client server1){
    var readFile=server1->get("/file.txt");
    match readFile{
        error err=>{
            io:println("An error occured");
            return err;
        }
        io:ByteChannel =>{
            io:println("Success");
            return readFile;
        }
    }
}

有人可以帮我解决这个问题吗

最佳答案

此处介绍了如何将端点作为参数传递给函数。

import ballerina/http;
import ballerina/io;

function main (string... args) {
    endpoint http:Client cheapAir {
        url: "http://localhost:9090/CheapAir"
    };

    invoke(cheapAir);
}

function invoke(http:Client client) {
    endpoint http:Client myEP = client;

    json reqPayload = {firstName:"Sameera", lastName:"Jayasoma"};
    http:Response response = check myEP -> post("/bookFlight", reqPayload);
    json resPayload = check response.getJsonPayload();
    io:println(resPayload);  
}

关于ftp - 如何将端点作为参数传递给 Ballerina 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51351030/

相关文章:

java - 从 Google App Engine 中的 FTP URL 读取文件,FileNotFoundException

java - 无效的 IPv6 地址

kubernetes - 芭蕾舞女 Actor “undefined package ”与Visual Code中的kubernetes

ballerina - 如何在 ballerina lang 中进行字符串填充

wso2 - 芭蕾舞女 Actor For Loop

java - 如何使用 FTP 协议(protocol)恢复读取输入流

java - 通过多个连接同时从 FTP 服务器下载同一文件的不同部分

c# - 如何在断开连接的情况下自动恢复下载 FTP 文件

java - FTPClient上传进度

java - Apache FTPClient 上传 jar 文件最终被损坏