crifurch / pure_ftp

MIT License
8 stars 3 forks source link

list directory sometimes fails #17

Closed abdelaziz-mahdy closed 4 months ago

abdelaziz-mahdy commented 4 months ago

this works

  Future<void> _listDirectory([FtpDirectory? dir]) async {

    final dirEntries = await ftpConnect!.fs.listDirectory(directory: dir);

  }

but this doesnt

Future<void> _listDirectory([FtpDirectory? dir]) async {
    if (dir != null) {
      bool result = await ftpConnect!.changeDirectory(dir.path);
      if (!result) {
        print('Failed to change directory');
      }
    }

    print("directory: ${ftpConnect!.currentDirectory}");

    final dirEntries = await ftpConnect!.fs.listDirectory();

  }

the logs

flutter: [2024-05-16 11:46:14.062234] 192.168.1.5:15114> NOOP
flutter: [2024-05-16 11:46:14.364556] 192.168.1.5:15114< 200 NOOP ok
flutter: [2024-05-16 11:46:14.365144] 192.168.1.5:15114> CWD /Anya
flutter: [2024-05-16 11:46:14.667542] 192.168.1.5:15114< 250 CWD successful
flutter: [2024-05-16 11:46:14.668692] 192.168.1.5:15114> NOOP
flutter: [2024-05-16 11:46:14.971165] 192.168.1.5:15114< 200 NOOP ok
flutter: [2024-05-16 11:46:14.971435] 192.168.1.5:15114> CWD /Anya
flutter: [2024-05-16 11:46:15.273821] 192.168.1.5:15114< 250 CWD successful
flutter: directory: FtpDirectory(path: /Anya)
flutter: [2024-05-16 11:46:15.275642] 192.168.1.5:15114> PASV
flutter: [2024-05-16 11:46:15.578904] 192.168.1.5:15114< 227 Entering Passive Mode (192,168,1,5,139,137).
flutter: [2024-05-16 11:46:15.617764] 192.168.1.5:15114> LIST /Anya
flutter: [2024-05-16 11:46:15.919893] 192.168.1.5:15114< 450 Couldn't list that file
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FtpException: Error while listing directory
#0      FtpFileSystem.listDirectory.<anonymous closure> (package:pure_ftp/src/file_system/ftp_file_system.dart:138:9)
<asynchronous suspension>
#1      FtpSocket._openTransferChannelPassive (package:pure_ftp/src/ftp/ftp_socket.dart:240:16)
<asynchronous suspension>
#2      FtpFileSystem.listDirectory (package:pure_ftp/src/file_system/ftp_file_system.dart:124:20)
<asynchronous suspension>
#3      _FTPHomePageState._listDirectory (package:ftp_client/main.dart:58:24)
<asynchronous suspension>
crifurch commented 4 months ago

are you have file with name Anya?

abdelaziz-mahdy commented 4 months ago

It's a directory,

The same directory works if I used the other code

I tested a lot of directories none of them work with the 2 code but all of them work using the first code

crifurch commented 4 months ago

Ok, thank you, i will investigate problem

crifurch commented 4 months ago

hmm for me works fine

crifurch commented 4 months ago

[2024-05-16 14:23:50.128214] localhost:21> PWD [2024-05-16 14:23:50.429664] localhost:21< 257 "/" is the current directory [2024-05-16 14:23:50.433038] localhost:21> NOOP [2024-05-16 14:23:50.733684] localhost:21< 200 NOOP ok. [2024-05-16 14:23:50.734494] localhost:21> CWD /test [2024-05-16 14:23:51.035693] localhost:21< 250 Directory successfully changed. [2024-05-16 14:23:51.036121] localhost:21> NOOP [2024-05-16 14:23:51.337646] localhost:21< 200 NOOP ok. [2024-05-16 14:23:51.337880] localhost:21> CWD /test [2024-05-16 14:23:51.638679] localhost:21< 250 Directory successfully changed. directory: FtpDirectory(path: /test) [2024-05-16 14:23:51.641598] localhost:21> PASV [2024-05-16 14:23:51.942716] localhost:21< 227 Entering Passive Mode (127,0,0,1,39,103). [2024-05-16 14:23:51.951404] localhost:21> LIST /test [2024-05-16 14:23:52.252670] localhost:21< 150 Here comes the directory listing. 226 Directory send OK. -rwxrwxrwx 1 1000 100 0 Jan 11 2023 test

crifurch commented 4 months ago

i need some more information

abdelaziz-mahdy commented 4 months ago

I will try to test on the dev branch, maybe your changes fixed it ?

crifurch commented 4 months ago

i tested on last 0.7.1 version

abdelaziz-mahdy commented 4 months ago

Will test and let you know. Thank you very much

abdelaziz-mahdy commented 4 months ago

still has the same problem

flutter: [2024-05-16 14:42:26.425663] 192.168.1.5:12378> NOOP
flutter: [2024-05-16 14:42:26.728003] 192.168.1.5:12378< 200 NOOP ok
flutter: [2024-05-16 14:42:26.730410] 192.168.1.5:12378> NOOP
flutter: [2024-05-16 14:42:27.033163] 192.168.1.5:12378< 200 NOOP ok
flutter: [2024-05-16 14:42:27.034392] 192.168.1.5:12378> CWD /Anya
flutter: [2024-05-16 14:42:27.337437] 192.168.1.5:12378< 250 CWD successful
flutter: [2024-05-16 14:42:27.338624] 192.168.1.5:12378> NOOP
flutter: [2024-05-16 14:42:27.641822] 192.168.1.5:12378< 200 NOOP ok
flutter: [2024-05-16 14:42:27.642464] 192.168.1.5:12378> CWD /Anya
flutter: [2024-05-16 14:42:27.945944] 192.168.1.5:12378< 250 CWD successful
flutter: directory: FtpDirectory(path: /Anya)
flutter: [2024-05-16 14:42:27.947516] 192.168.1.5:12378> PASV
flutter: [2024-05-16 14:42:28.250683] 192.168.1.5:12378< 227 Entering Passive Mode (192,168,1,5,143,149).
flutter: [2024-05-16 14:42:28.375558] 192.168.1.5:12378> LIST /Anya
flutter: [2024-05-16 14:42:28.678570] 192.168.1.5:12378< 450 Couldn't list that file
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FtpException: Error while listing directory
#0      FtpFileSystem.listDirectory.<anonymous closure> (package:pure_ftp/src/file_system/ftp_file_system.dart:138:9)
<asynchronous suspension>
#1      FtpSocket._openTransferChannelPassive (package:pure_ftp/src/ftp/ftp_socket.dart:240:16)
<asynchronous suspension>
#2      FtpFileSystem.listDirectory (package:pure_ftp/src/file_system/ftp_file_system.dart:126:20)
<asynchronous suspension>
#3      _FTPHomePageState._listDirectory (package:ftp_client/main.dart:74:24)
<asynchronous suspension>

using the first code gets me

flutter: [2024-05-16 14:42:04.555240] 192.168.1.5:12378> NOOP
flutter: [2024-05-16 14:42:04.857680] 192.168.1.5:12378< 200 NOOP ok
flutter: directory: FtpDirectory(path: /)
flutter: [2024-05-16 14:42:04.857983] 192.168.1.5:12378> PASV
flutter: [2024-05-16 14:42:05.160958] 192.168.1.5:12378< 227 Entering Passive Mode (192,168,1,5,173,209).
flutter: [2024-05-16 14:42:05.231071] 192.168.1.5:12378> LIST /Anya
flutter: [2024-05-16 14:42:05.534064] 192.168.1.5:12378< 150 Opening ASCII mode data connection for file list
226 Data transmission OK
flutter: -rw-r--r-- 1 owner group      9525945 May 21 19:22 Desktop.rar
drwxr-xr-x 1 owner group         3452 May 21 19:23 Desktop
crifurch commented 4 months ago

which ftp server you are use?

abdelaziz-mahdy commented 4 months ago

i am using ftp server on mobile, https://play.google.com/store/apps/details?id=com.mi.android.globalFileexplorer&hl=en&gl=US

abdelaziz-mahdy commented 4 months ago

doesnt work

image
abdelaziz-mahdy commented 4 months ago

i am not blocked by that problem,

i manage the current directory in the app, and list the one i want using the code that works, so if its something related to my ftp i guess no need to fix it,

    currentDirectory = dir ?? ftpConnect!.currentDirectory;
    final dirEntries = await ftpConnect!.fs.listDirectory(directory: dir);

this is what i am doing to list the directory i want

crifurch commented 4 months ago

@abdelaziz-mahdy try this branch https://github.com/crifurch/pure_ftp/tree/test_list_dir

abdelaziz-mahdy commented 4 months ago

Nice that one made the two codes work

I guess the fix was making list call without parameters?

crifurch commented 4 months ago

Yes, little bit later i will add it to master brunch and release new version