Skip to content

fix(files_external): skip BSD ftpd total N listing headers - #63197

Open
xusnitdinov wants to merge 1 commit into
nextcloud:masterfrom
xusnitdinov:fix/ftp-bsd-total-header
Open

fix(files_external): skip BSD ftpd total N listing headers#63197
xusnitdinov wants to merge 1 commit into
nextcloud:masterfrom
xusnitdinov:fix/ftp-bsd-total-header

Conversation

@xusnitdinov

Copy link
Copy Markdown

Summary

  • BSD ftpd prepends LIST output with a total N line. The raw-list fallback in FtpConnection tried to parse that as a file entry and threw Metadata can't be parsed from item 'total 17'.
  • Skip empty lines and total headers the same way flysystem does. . / .. are still parsed as cdir / pdir.

Fixes #37045

Checklist

  • Code is from this PR's author
  • Signed-off-by is in the commit
  • Tests added where possible (parser is private; existing FTP tests are integration-only against a live server)

Made with Cursor

@xusnitdinov
xusnitdinov requested a review from a team as a code owner August 13, 2026 06:18
@xusnitdinov
xusnitdinov requested review from CarlSchwan, icewind1991, provokateurin and sorbaugh and removed request for a team August 13, 2026 06:18
@github-actions

Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@joshtrichards joshtrichards added this to the Nextcloud 36 milestone Aug 28, 2026
$filtered = array_values(array_filter($rawList, static function (string $item): bool {
$item = trim($item);
// BSD ftpd (and some Unix servers) prepend listings with a "total N" header
return $item !== '' && !preg_match('/^total\b/i', $item);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return $item !== '' && !preg_match('/^total\b/i', $item);
return !str_starts_with($item, 'total ');

This is a lot cheaper.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, good call. Though the $item !== '' check still needed too since array_filter() being used with callback.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean. Empty lines or lines with only whitespace weren't filtered out before, so why should they now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that str_starts_with() only replaces the regex part of the condition. If we still intend to exclude empty/whitespace-only lines as described in the PR, $item !== '' remains necessary because array_filter() has a callback and therefore won't filter out empty values automatically. Without that check, str_starts_with() returns false for an empty haystack, so the negated condition returns true; the empty line then reaches the parser and causes the same "not enough parts" exception.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but I don't see any explanation why filtering out empty lines is necessary.

@joshtrichards

Copy link
Copy Markdown
Member

/backport to stable35

@joshtrichards

Copy link
Copy Markdown
Member

/backport to stable34

@joshtrichards

Copy link
Copy Markdown
Member

/backport to stable33

@joshtrichards

Copy link
Copy Markdown
Member

/backport to stable32

BSD ftpd prepends directory listings with a `total N` line. The raw
LIST parser treated that as a file entry and threw, so external FTP
storage against FreeBSD could not be browsed.

Skip empty lines and `total` headers the same way flysystem does,
while still parsing `.` / `..` as cdir/pdir.

Fixes: nextcloud#37045

Signed-off-by: Xusnitdinov Azizbek <252487890+xusnitdinov@users.noreply.github.com>
@joshtrichards
joshtrichards force-pushed the fix/ftp-bsd-total-header branch from bdc1f4e to 758a226 Compare September 2, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: External Storage against BSD ftp server failing due to parsing difference

3 participants