I'm using node, and the node-ftp module. I need to upload two files to another server, I'm able to upload one file, but when I try uploading two files it throws back and error.
according to their api, this is the code for sending a file
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();
});
which works fine, but if i want to do two file I assume I would have to just repeat that function, but it won't work. Does anyone know how to send two or more files using FTPClient
here is the the code I'm trying to execute
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();
update: I tried this as well, but it won't connect again.
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();
});
});
Don't end the connection until both files are uploaded in series:
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();
});
});
}
);