Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload/download progress #293

Open
fuzunspm opened this issue Sep 14, 2018 · 2 comments
Open

upload/download progress #293

fuzunspm opened this issue Sep 14, 2018 · 2 comments

Comments

@fuzunspm
Copy link

not an issue but can someone guide/teach me to console.log download/upload progress?

@emko
Copy link

emko commented Sep 18, 2018

yes i am looking to know how to do this too so i can show the progress of a transfer to the user

@broofa
Copy link

broofa commented Sep 28, 2018

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants