patrickjuchli / basic-ftp

FTP client for Node.js, supports FTPS over TLS, passive mode over IPv6, async/await, and Typescript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

downloadToStream Error

mgrist opened this issue · comments

I am getting an error when trying to use the downloadTo() method. Here is the code I am trying to run. The hostname and file name have been changed for privacy purposes. I checked and it is successfully connecting to the host.

try {
  const client = new ftp.Client();
  //client.ftp.verbose = true
  await client.access({
    host: "hostname",
    user: TR_FTP_USERNAME,
    password: TR_FTP_PASSWORD,
  });

  const writeStream = new stream.Writable();
  await client.downloadTo(writeStream, "filename");
  writeStream.pipe(process.stdout);
  client.close();
  return { message: "success" };
} catch (e) {
  console.log("--- Critical ---");
  console.log(e);
  throw e;
}

I am receiving the following error:
ERROR Uncaught Exception {"errorType":"Error","errorMessage":"The _write() method is not implemented","code":"ERR_METHOD_NOT_IMPLEMENTED","stack":["Error [ERR_METHOD_NOT_IMPLEMENTED]: The _write() method is not implemented"," at new NodeError (internal/errors.js:322:7)"," at Duplex.Writable._write (internal/streams/writable.js:548:11)"," at writeOrBuffer (internal/streams/writable.js:358:12)"," at Duplex.Writable.write (internal/streams/writable.js:303:10)"," at Socket.ondata (internal/streams/readable.js:731:22)"," at Socket.emit (events.js:400:28)"," at Socket.Readable.read (internal/streams/readable.js:504:10)"," at Socket.read (net.js:638:39)"," at flow (internal/streams/readable.js:986:34)"," at resume_ (internal/streams/readable.js:967:3)"]}

Am I supposed to define my own _write() function?

Yes, you are, or you could use another way to build streams. I will close this ticket because the issue is not specific to this library but rather about Node.js and how to work with streams.