Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transfer get stuck #278

Open
MetaiR opened this issue Feb 19, 2022 · 0 comments
Open

transfer get stuck #278

MetaiR opened this issue Feb 19, 2022 · 0 comments

Comments

@MetaiR
Copy link

MetaiR commented Feb 19, 2022

hi,
when I use this library to download or upload files on some devices it got stuck at some random point and nothing happen, no error or retry or anything, it just got stuck, what can cause it?

my code:

         download() {
                client.get(path, (e, stream) => {
                      if (e) {
                          console.log('ftp face error for downloading id: ' + someId);
                          this.emitDownloadEvent(this.getDownloadProgressObj(someOtherId, someId, 0, 'ERROR', err));
                          reject();
                          return;
                      }
                      this.emitDownloadCalculatedPercentage(stream, someOtherId, someId, bytes);

                      FileUtil.createDirIfNotExists(videoStorage);

                      const output = fs.createWriteStream(savingPath);
                      stream.pipe(output);

                      output.on('close', () => {
                          console.log('ftp completed for downloading id: ' + someId);
                          this.emitDownloadEvent(this.getDownloadProgressObj(someOtherId, someId, 100, 'COMPLETED'));
                          client.end();
                          resolve();
                      });
                  });
         }
        
        private getDownloadProgressObj(someOtherId: number, someId: string, progress = 0, status: 'CONNECTED' | 'DOWNLOADING' | 'COMPLETED' | 'ERROR' = 'CONNECTED', ex?: Error): FtpProgress {
        return {
            someOtherId: someOtherId,
            type: 'DOWNLOAD',
            someId: someId,
            progress: progress,
            status: status,
            ex: ex
        };
    }

       private emitDownloadCalculatedPercentage(file: NodeJS.ReadableStream, someOtherId: number, someId: string, size: number) {
        let cur = 0;
        file.on('data', (d) => {
            cur += d.length;
            const percent = ((cur / size) * 100).toFixed(1);
            this.emitDownloadEvent(this.getDownloadProgressObj(someOtherId, someId, Number(percent), 'DOWNLOADING'));
        });
    }

    private emitDownloadEvent(progress: FtpProgress) {
        console.log(progress);
        FtpUtil.transferEvent.emit('download', progress);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant