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

REQ: Obtain a PUT write stream

Open ghost opened this issue 6 years ago • 0 comments

Hi and thanks for updating this project.

Would it be feasible to expose a PUT write stream (or its socket) in a clean way?

Much like get() which provides a read stream, but with put() we can only set a file name. It would be very nice to have something like putStream() which we then can write arbitrarily to.

You could do interesting things with one, such as for instance piping different source files into a single ZIP archive on the FTP server.:

// see: https://github.com/archiverjs/node-archiver
var archive = archiver('zip', { zlib: { level: 9 }});

// .. connect to FTP server and obtain a FTP write stream:
var ftpWriteStream = ftpClient.putStream('filename.zip'):

archive.pipe(ftpWriteStream);  // here!

archive.append(someReadStream1, { name: 'file1.txt' });
archive.append(someReadStream2, { name: 'file2.txt' });
archive.append(someReadStream3, { name: 'file2.txt' });
archive.finalize();

//...
// Done, and one single file created directly on the FTP server
// with no need for temp on local.

Pseudo implementation:

client.putStream = function(file, callback) {
  issue STOR cmd + checks on command socket
  if OK callback with data socket
}

ghost avatar Apr 21 '19 21:04 ghost