spmjs / node-scp2

[MAINTAINER WANTED] A pure javascript scp program based on ssh2.
385 stars 96 forks source link

Files over 65536 bytes get corrupted on download #5

Closed aversini closed 10 years ago

aversini commented 10 years ago

Downloading any type of files works great, unless their size is over 65536 bytes.

For files over 65k, it looks like the download went well (no err in the callback) but they get corrupted after the first 65536 bytes. I can attach an example of a file before and after if needed.

I also tried over an external network, as well as a local network (guest + vm) but the issue remains.

I may be missing some special configuration for larger files?

Here is the testing code I'm using:

var client = require('scp2');
  client.scp({
    host: 'the-remote-host',
    username: 'the-remote-username',
    password: 'the-remote-password',
    path: path.join('/tmp', 'file.tar')
  }, path.join(process.cwd(), 'file.tar'), function (err) {
    if (err) {
      console.log('Unable to get the file back! ');
      client.close();
    } else {
      console.log('File downloaded successfully');
      client.close();
    }
  });

Let me know if I can do anything else to help... Thanks!

lepture commented 10 years ago

@aversini I know where the bug is. Coz u can't read all bytes into memory. Look at code line 286 - 196, we need to read some bytes (not all) and write them, then read another some bytes, write them, read and write, until finished.

nodesocket commented 10 years ago

Is this issue fixed?