gpt4 book ai didi

node.js - 无法使用 FTPClient node.js 模块上传两个或多个文件

转载 作者:太空宇宙 更新时间:2023-11-03 23:10:51 24 4
gpt4 key购买 nike

我正在使用node和node-ftp模块。我需要将两个文件上传到另一台服务器,我可以上传一个文件,但是当我尝试上传两个文件时,它会返回错误。

根据他们的api,这是发送文件的代码

var fs = require('fs');
conn.put(fs.createReadStream('/var/www/videoComplete/'+ videoID +'.flv'), '/home/wowza/content/'+ videoID +'.flv', function(e) {
console.log(fileName + '.flv uploaded to Streaming Server :)');
conn.end();
});

它工作正常,但如果我想做两个文件,我假设我必须重复该功能,但它不起作用。有谁知道如何使用 FTPClient 发送两个或多个文件

这是我尝试执行的代码

conn = new FTPClient({ host: 'serverIP' });
conn.on('connect', function() {
conn.auth('user', 'pass', function(e) {
if (e) throw e;
var fs = require('fs');

conn.put(fs.createReadStream('/var/www/ce-videoComplete/'+ videoID +'.flv'), '/home/wowza/content/'+ videoID +'.flv', function(e) {
console.log(fileName + '.flv uploaded to Streaming Server :)');
conn.end();
});

conn.put(fs.createReadStream('/var/www/ce-thumbnails/'+ videoID +'.jpg'), '/var/www/html/thumbnails/'+ videoID +'.jpg', function(e) {
console.log(fileName + '.jpg uploaded to Streaming Server :)');
conn.end();
});

});
});
conn.connect();

更新:我也尝试过,但无法再次连接。

conn.put(fs.createReadStream('/var/www/ce-videoComplete/'+ videoID +'.flv'), '/home/wowza/content/'+ videoID +'.flv', function(e) {
console.log(fileName + '.flv uploaded to Streaming Server :)');
conn.end();

conn.put(fs.createReadStream('/var/www/ce-thumbnails/'+ videoID +'.jpg'), '/var/www/html/thumbnails/'+ videoID +'.jpg', function(e) {
console.log(fileName + '.jpg uploaded to Streaming Server :)');
conn.end();
});
});

最佳答案

在两个文件连续上传之前不要结束连接:

conn.put(fs.createReadStream('/var/www/ce-videoComplete/'+ videoID +'.flv'), 
'/home/wowza/content/'+ videoID +'.flv',
function(e) {
console.log(fileName + '.flv uploaded to Streaming Server :)');

conn.put(fs.createReadStream('/var/www/ce-thumbnails/'+ videoID +'.jpg'),
'/var/www/html/thumbnails/'+ videoID +'.jpg',
function(e) {
console.log(fileName + '.jpg uploaded to Streaming Server :)');
// Now that both files are uploaded, end the connection.
conn.end();
});
});
}
);

关于node.js - 无法使用 FTPClient node.js 模块上传两个或多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12163359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com