#53318 closed defect (bug) (duplicate)
FTPext method exists() returns always false for files!
Reported by: | arl1nd | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.7.2 |
Component: | Filesystem API | Keywords: | needs-patch dev-feedback |
Focuses: | docs | Cc: |
Description
Hi there,
Are you aware that WP_Filesystem_FTPext method exists( $file ) only checks for existence of directory, giving file path as argument will always return false!
wp-admin/includes/class-wp-filesystem-ftpext.php
The original method code:
public function exists( $file ) { $list = ftp_nlist( $this->link, $file ); if ( empty( $list ) && $this->is_dir( $file ) ) { return true; // File is an empty directory. } return ! empty( $list ); // Empty list = no file, so invert. }
If you check the PHP manual for ftp_nlist it only accepts directory as input value.
Any thoughts?
Attachments (1)
Change History (7)
Note: See
TracTickets for help on using
tickets.
This seems not to be working properly from PHP manuals, but from RFC959(https://www.ietf.org/rfc/rfc959.txt page 32) it looks well.
As ftp_nlist is using ftp list and ftp list supports both directories and files with a result, it works out.
It seems to work and there is a good explanation at stackoverflow: https://stackoverflow.com/questions/22040633/php-check-if-file-exists-on-ftp-server-with-no-size-support
Anyway there is no other clean way to determine if a file exists without downloading it. Other solutions like ftp_size are not supported by all servers.
Maybe this could be documented within the method as well, I will leave a patch here.
The discussion why someone wants to check for existing files/dirs at all is another story.