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

listDirectoryContent() gets stuck with message "about to open data connection" #19

Open
aziztitu opened this issue Jan 17, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@aziztitu
Copy link

aziztitu commented Jan 17, 2021

Describe the bug
The listDirectoryContent() method gets stuck indefinitely. If the debug is set to true, we can see this log:

I/flutter ( 4570): [17.01.2021 15:14:43.636] Connecting...
I/flutter ( 4570): [17.01.2021 15:14:43.840] < 220 Service ready for new user.
I/flutter ( 4570): [17.01.2021 15:14:43.841] > USER anonymous
I/flutter ( 4570): [17.01.2021 15:14:44.144] < 331 Guest login okay, send your complete e-mail address as password.
I/flutter ( 4570): [17.01.2021 15:14:44.144] > PASS
I/flutter ( 4570): [17.01.2021 15:14:44.246] < 230 User logged in, proceed.
I/flutter ( 4570): [17.01.2021 15:14:44.246] Connected!
I/flutter ( 4570): Connected successfully
I/flutter ( 4570): [17.01.2021 15:14:44.250] > PWD
I/flutter ( 4570): [17.01.2021 15:14:44.351] < 257 "/" is current directory.
I/flutter ( 4570): /
I/flutter ( 4570): [17.01.2021 15:14:44.354] > TYPE A
I/flutter ( 4570): [17.01.2021 15:14:44.455] < 200 Command TYPE okay.
I/flutter ( 4570): [17.01.2021 15:14:44.455] > PASV
I/flutter ( 4570): [17.01.2021 15:14:44.556] < 227 Entering Passive Mode (192,168,1,8,167,251)
I/flutter ( 4570): [17.01.2021 15:14:44.558] > MLSD
I/flutter ( 4570): [17.01.2021 15:14:44.569] < 150 File status okay; about to open data connection.

And it gets stuck at this point. The listDirectoryContent() method never returns.

Code Snippet:

FTPClient ftpClient = FTPClient(host.text,
            port: int.parse(port.text),
            user: username.text.isEmpty ? "anonymous" : username.text,
            pass: password.text,
            debug: true);
ftpClient.connect();     

debugPrint("Connected successfully");
debugPrint(ftpClient.currentDirectory());

var dirs = ftpClient.listDirectoryContent();         // <-- It gets stuck here
ftpClient.disconnect();

for (var dir in dirs) {
  debugPrint(dir.name);
}

Expected behavior
listDirectoryContent() returns the directory content, or throws a proper error.

Platform:

  • Flutter

Smartphone (when using Flutter):

  • Device: OnePlus 8 Pro
  • OS: Oxygen OS 11.0.2.2 [Android Version 11]

FTP Server Software

  • Dragon Touch Picture Frame FTP
@aziztitu aziztitu added the bug Something isn't working label Jan 17, 2021
@aziztitu aziztitu changed the title connect() gets stuck with message "about to open data connection" listDirectoryContent() gets stuck with message "about to open data connection" Jan 17, 2021
@aziztitu
Copy link
Author

aziztitu commented Jan 18, 2021

Upon further inspection at the source code, I think I've figured out the issue.

This bug occurs when the current directory in the FTP Server is empty. This following loop in directory.dart never exits if there is no file/directory in the current directory.

int iToRead = 0;
List<int> lstDirectoryListing = List<int>();
do {
if (iToRead > 0) {
List<int> buffer = List<int>(iToRead);
dataSocket.readIntoSync(buffer);
buffer.forEach(lstDirectoryListing.add);
}
iToRead = dataSocket.available();
if (iToRead == 0 || lstDirectoryListing.isEmpty) {
sleep(Duration(milliseconds: 500));
iToRead = dataSocket.available();
}
} while (iToRead > 0 || lstDirectoryListing.isEmpty);

A simple change in logic here would fix the issue. I can create a PR later for this if you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant