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

Can't get the whole file sometimes

Open taozi0818 opened this issue 6 years ago • 8 comments

I want to download some files from FTP server.But i cannot get the whole file when i use get() method. For example, the size of file which i want to download is 200000 bytes, when i get 199000 bytes (99%) of the file, the download progress will pause or stop.But, stream and connection can't catch any errors or trigger any events(trigger close event sometimes).

taozi0818 avatar Oct 19 '17 03:10 taozi0818

Yes, sometimes it happens with me. I don't know why it does.

icetee avatar Oct 29 '17 18:10 icetee

I resolved this with another library.... But something go wrong when connect to FTP server with that library.

taozi0818 avatar Oct 29 '17 19:10 taozi0818

Which library did you use?

Bestulo avatar Nov 27 '17 22:11 Bestulo

@Besatnias jsftp. But this library is not good at handling error.you cannot detail information about error sometimes.

taozi0818 avatar Nov 29 '17 10:11 taozi0818

I'm getting this issue as well. I'm needing to download about 30gb split into 3gb files every day. When the script is running on gigabit internet, all the downloads succeed. When running on 50mbps internet, the downloads will just completely stop if they don't download fast enough. I don't think it's the ftp server that's dropping me since I can download them through chrome just fine using the ftp://url

JourdanClark avatar Aug 22 '18 16:08 JourdanClark

I'm also listening to every event on stream and client and nothing happens. I also noticed that on slower internet, when I was downloading a 110mb file, the download would finish and it would just sit there for about 40 seconds before it would close the stream and end the client. On fast internet, the client would end as soon as the download finished.

JourdanClark avatar Aug 22 '18 16:08 JourdanClark

@JourdanClark You can test it again with this library jsftphttps://github.com/sergi/jsftp. Hope it can help you.

taozi0818 avatar Aug 22 '18 17:08 taozi0818

For those also having issues with not getting the whole file, it seems related to small files over fast networks as described by @polidore on https://github.com/mscdex/node-ftp/issues/70#issuecomment-34785017 (the file I was having issues with was 142kb over a 700Mbps connection). This snippet worked for me (based on a workaround by @ugate on https://github.com/mscdex/node-ftp/issues/66):

const FTP = new ftp();
const FILE = "MyFile.txt";
const PASSTHROUGH = new require("stream").PassThrough();

FTP.get(FILE, (error, stream) => {
  if (error) {
    console.log(`ERROR: ${error.message}`);
    throw error;
  } else {
    stream.pipe(PASSTHROUGH),
      FILE,
      error => {
        if (error) {
          console.log(`ERROR: ${error.message}`);
          throw error;
        } else {
          // in my case I'm writing to a temporary file, but you can do whatever is needed at this point
          fs.createWriteStream(path.join("/tmp", "data.tsv"));
        }
      };

    PASSTHROUGH.end(() => {
      FTP.end();
      console.log("Closed FTP connection. Goodbye!");
    });
  }
});

Documentation on stream.PassThrough can be found here: https://nodejs.org/api/stream.html#stream_class_stream_passthrough

rlueder avatar Feb 28 '20 18:02 rlueder