Skip to content

transfer get stuck #278

Description

@MetaiR

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);
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions