我正在使用 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();
});
});