crifurch / pure_ftp

MIT License
8 stars 3 forks source link

download never completes? #24

Closed abdelaziz-mahdy closed 4 months ago

abdelaziz-mahdy commented 4 months ago

i think the download function is waiting for a command


flutter: [2024-05-17 17:03:35.753097] 192.168.1.5:60859> SIZE /Anya/Desktop/Screenshot 2022-05-21 190952.png
flutter: [2024-05-17 17:03:36.057139] 192.168.1.5:60859< 550 No directory traversal allowed in SIZE param
flutter: [2024-05-17 17:03:36.058355] 192.168.1.5:60859> PASV
flutter: [2024-05-17 17:03:36.361158] 192.168.1.5:60859< 227 Entering Passive Mode (192,168,1,5,181,75).
flutter: [2024-05-17 17:03:36.397860] 192.168.1.5:60859> RETR /Anya/Desktop/Screenshot 2022-05-21 190952.png
flutter: [2024-05-17 17:03:36.700702] 192.168.1.5:60859< 150 Sending file
226 Transmission finished
flutter: downloaded: 215402 of 215402, 100.0% calculated 100.0%, speed: Infinity MB/second
flutter: Downloaded 215402 of 215402 bytes
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FtpException: Timeout reached for Receiving response!
#0      FtpSocket.read.<anonymous closure> (package:pure_ftp/src/ftp/ftp_socket.dart:163:7)
#1      _RootZone.run (dart:async/zone.dart:1655:54)
#2      Future.timeout.<anonymous closure> (dart:async/future_impl.dart:943:34)
#3      Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
#4      _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
#5      _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
#6      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

but if that command is 226 Transmission finished it got sent, but looks like it got sent before the file could finish copying

anyway to know what is the problem?

abdelaziz-mahdy commented 4 months ago

tested using another ftp server, that the message gets sent after finishing the copying

image

it works correctly there.

crifurch commented 4 months ago

oh, i'm found problem

crifurch commented 4 months ago

i will try fix it in few moments

crifurch commented 4 months ago

@abdelaziz-mahdy try this https://github.com/crifurch/pure_ftp/tree/fix/dowload_wait_response_error, i tested on large file? i think it is not necessary to wait some response after download

crifurch commented 4 months ago

now it should works as expected

abdelaziz-mahdy commented 4 months ago

the flush is needed, i will test again, since the files gets downloaded but corrupted

crifurch commented 4 months ago

pls try test in now, remove pubspec.lock before pub get

abdelaziz-mahdy commented 4 months ago

btw flutter upgrade should get the updated without the need to delete the lock, but will try it

crifurch commented 4 months ago

and don't forget change to binary transfer if you are download some not text filles

abdelaziz-mahdy commented 4 months ago

changing to binary fixed the corrupted problem, should that be the default? most of the ftp downloads are not text files if i am correct client.socket.setTransferType(FtpTransferType.binary);

crifurch commented 4 months ago

in auto mode i had

Downloaded 24467980 of 24468684 bytes
Downloaded 24469428 of 24469428 bytes

if i used await client.socket.setTransferType(FtpTransferType.binary);

i had only

Downloaded 24468304 of 24468684 bytes
Downloaded 24468684 of 24468684 bytes
Disconnecting from 192.168.1.200:21
crifurch commented 4 months ago

changing to binary fixed the corrupted problem, should that be the default? most of the ftp downloads are not text files if i am correct client.socket.setTransferType(FtpTransferType.binary);

i think yes but in many cases ftp clients use auto mode as default

crifurch commented 4 months ago

you can use

FtpClient(
    socketInitOptions: FtpSocketInitOptions(
      host: config['host'],
      port: config['port'],
      transferType: FtpTransferType.binary,
    ),
    authOptions: FtpAuthOptions(
      username: config['username'],
      password: config['password'],
      account: config['account'],
    ),
    logCallback: print,
  );
abdelaziz-mahdy commented 4 months ago

okay thank you very much, the download completes using the mentioned branch

crifurch commented 4 months ago

ok, i will update package now