node-ftp icon indicating copy to clipboard operation
node-ftp copied to clipboard

put method creates file but does not write in it

Open INanaay opened this issue 6 years ago • 2 comments

I've been trying to upload a local file to my ftp server.

I've created a readable stream from the path of my file like so :

const stream = fs.createWriteStream(path);

Then, on the end event of the stream, I call the put method :

` stream.on('end', () => { client.connect(config);

client.on('close', (hadErr) => {
  logger.log('info', `client upload closed ${hadErr}`);
});

client.on('error', (err) => {
  logger.log('error', `client upload error ${err}`);
  client.end();
});

client.on('ready', () => {
  client.mkdir(Path.dirname(path), true, (err) => {
    if (err) {
      logger.log('error', `upload mkdir error ${err}`);
      client.end();
    }

    client.put(stream, path, (err) => {
      stream.on('error', (err) => {
        logger.log('error', `upload stream error ${err}`);
        client.end();
      });

      if (err) {
        logger.log('error', `upload put error ${err}`);
        stream.destroy();
        client.end();
        return;
      }

      client.end();
    });
  });
});
})

`

I see my file on the server but it has a size of 0 bytes. Is there something I'm missing here ?

Edit : After deleting the stream.on('data') event, the file is sucessfully transfered, I really don't understand,

INanaay avatar May 17 '19 09:05 INanaay

same problem here.

MaxDesplanches avatar Jun 17 '19 09:06 MaxDesplanches

Same problem-- it worked for months and then all of a sudden stopped.

ACMotanya avatar Feb 07 '20 16:02 ACMotanya