问题描述
我正在研究一个系统,该系统每隔1分钟自动从FTP服务器读取CSV文件,将其转换为XML文件,然后将XML文件存储到FTP服务器。我正在使用txt文件进行测试。但是,我仍然遇到此错误:
@H_502_2@if (err) throw err;
^
Error: Unable to make data connection
at Socket.<anonymous>
这是我的代码:
@H_502_2@const cron = require("node-cron");
const express = require("express");
var Client = require('ftp');
var fs = require('fs');
app = express();
// schedule tasks to be run on the server
cron.schedule("* * * * *",function () {
console.log("Running Cron Job");
var c = new Client();
var connectionProperties = {
host: "192.168.1.101",user: "Smoke2eZ",password: "Ngoclinh2906",}
c.on('ready',function () {
c.get('foo.txt',function (err,stream) {
if (err) throw err;
stream.once('close',function () {
c.end();
});
stream.pipe(fs.createWriteStream('input/foo.local-copy.txt'));
});
c.put('foo.txt','foo.remote-copy.txt',function (err) {
if (err) throw err;
c.end();
});
})
c.connect(connectionProperties);
});
app.listen(8000);