1

I've been using https://github.com/patrickjuchli/basic-ftp

There code that I've been working on, and have a problem with using the upload. the standard code is await client.upload(fs.createReadStream("README.md"), "README.md")

the README.md on fs.createReadStream("README.md") is the file that is already at the directory

but on the code that I'm working on is generated on the javascript like this:

const os = require('os');

const output = []

const data = [{subject:'Math', grade: 85},{subject:'Art', grade: 80},..]

data.forEach((d) => {
  output.push(
    d.subject+ "\t"
    + d.grade+ "\n");
});

var dataTXT = output.join(os.EOL);

await client.upload(dataTXT , "filename.txt")

the problem is, the file that is sent was empty.

is there another way of implementing it, or I have to use fs.createReadStream but there is no file/data that is can provide because is still on the code. And I can't do fs.writeFile because of this code will be launch of a server later on.

ceving
  • 21,900
  • 13
  • 104
  • 178
  • I don't knew the API but I notice you're supposed to call `client.access` to connect to an FTP server before calling `client.upload`. Have you done so, was the empty file that was sent retrieved on the FTP server? – Aaron May 03 '19 at 08:26
  • And if that's not the problem then [this question](https://stackoverflow.com/questions/12755997/how-to-create-streams-from-string-in-node-js) describes how to build ReadableStreams from strings (also "don't knew" -> "didn't know", yuk... too late to edit) – Aaron May 03 '19 at 08:33

0 Answers0