upload/download progress
fuzunspm opened this issue · 2 comments
fuzunspm commented
not an issue but can someone guide/teach me to console.log download/upload progress?
emko commented
yes i am looking to know how to do this too so i can show the progress of a transfer to the user
broofa commented
https://github.com/sergi/jsftp#ftpgetremotepath-callback will provide a Stream
that you can listen to data
events on. E.g.
client.get('your_file_here.txt', (err, socket) => {
if (err) return console.log(err);
const chunks = [];
// `data` events to gather data, log progress
socket.on('data', data => {
console.log(`Received ${data.length} bytes`);
chunks.push(data);
});
socket.on('end', () => {
const contents = Buffer.concat(chunks);
// (assuming contents are utf-8 encoded here
console.log('File contents', contents.toString('utf8'));
});
socket.resume();
});
Unfortunately put()
takes a Buffer, not a Stream, so I'm not sure there's a simple way to monitor upload progress. (Disclaimer: My experience with this module is limited to the above code so far, so this is not a canonical answer by any means.)