简体   繁体   English

Bluemix Nodejs FileTransferStep,文档

[英]Bluemix Nodejs FileTransferStep, documentation

I am a newbie to bluemix. 我是bluemix的新手。 I downloaded the client libraries. 我下载了客户端库。 But I don't see API docs for Javascript. 但是我看不到Javascript的API文档。 Where do I find that? 我在哪里找到的? How do I go about calling several of javascript functions which is neither in the nodejs client libs nor I could find it online? 我该如何去调用既不在nodejs客户端库中也不能在线找到的几个javascript函数?

about the Workload service call you have to edit your package.json file to add a dependency on the iws-light module using an https link, as follows 关于Workload服务调用,您必须编辑package.json文件以使用https链接在iws-light模块上添加依赖项,如下所示

"dependencies": {
    "iws-light": "https://start.wa.ibmserviceengage.com/bluemix/iws-light.tgz"
}

then you have to open your shell, go to the root of your app and run: 然后必须打开外壳,转到应用程序的根目录并运行:

npm install

after this you can require the Workload Scheduler service in your application: 之后,您可以在应用程序中需要Workload Scheduler服务:

var ws = require("iws-light");

and create a connection to Bluemix: 并创建到Bluemix的连接:

    //retrieve service URL from Bluemix VCAP_SERVICES...
    var wsConn;
    if(process.env.VCAP_SERVICES) {
        wsConn = ws.createConnection();
    } else {
        //...or set it on your own(if you're working in local)
        var url = "your workload scheduler url";
        wsConn = ws.createConnection(url);
    }

    //retrieve cloud agent 
    var agentName;
    wsConn.getCloudAgent(function(data) {
        agentName = data;
    });

    //set your timezone
    wsConn.setTimezone({timezone: "Europe/Rome"}, function(err, data){
        if(err){
            console.log(err);
        }
    });

now you're ready to use the lib and create a process and add to it a FileTransferStep: 现在您可以使用该库并创建一个进程,并向其中添加一个FileTransferStep:

    //create a process
    var process = new ws.WAProcess("ProcessName", "This process transfer a file every day from local to remote server");

    //supported operations are ws.steps.FileTransferStep.OperationDownload or ws.steps.FileTransferStep.OperationUpload
    var operation = ws.steps.FileTransferStep.OperationUpload;


    //create FileTransferStep
    var ftStep = new ws.steps.FileTransferStep(agentName, operation);

    //supported protocols are AUTO, FTP, FTPS, SSH, WINDOWS;
    ftStep.setProtocol(ws.steps.FileTransferStep.ProtocolAuto);

    //set local file
    var local = {
        path: "local file path",
        user: "local username",
        password: "local password"
    };
    ftStep.setLocalFile(local.path, local.user, local.password);

    //set remote file
    var remote = {
        path: "remote file path",
        user: "remote username",
        password: "remote password",
        server: "remote server"
    };
    ftStep.setRemoteFile(remote.server, remote.path, remote.user, remote.password);

    //the binary mode flag: true if it uses FTP binary mode
    var binaryMode = true;
    the passive mode flag: true if it uses FTP passive mode
    var passiveMode = true;
    //set timeout
    var timeout = 5;
    ftStep.setMode(binaryMode, passiveMode , timeout);

    //add FileTransferStep to the process
    process.addStep(ftStep);

    //create a trigger
    var trigger = new ws.TriggerFactory.everyDayAt(1, 7, 30);

    //add Trigger to the process
    process.addTrigger(trigger);

    process.tasklibraryid = "your task library id";

    //create and enable process
    wsConn.createAndEnableProcess(process, function(err, data){
        if(err){
            console.log(error);
        } else{
            console.log("process created and enabled");
        }
    });

The code above creates a process using a file transfer step from node.js code, however I'm not sure if this is what you actually need. 上面的代码使用来自node.js代码的文件传输步骤创建了一个过程,但是我不确定这是否是您真正需要的。 If you can explain the scenario you are trying to implement, I can be more precise about which is the best way to implement this scenario using Workload Scheduler service. 如果您可以解释您要实施的方案,那么我可以更精确地了解哪种方法是使用Workload Scheduler服务实施此方案的最佳方法。

Regards, Gabriele 问候,加布里埃莱

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM