diff --git a/src/wp-admin/includes/class-wp-filesystem-ftpext.php b/src/wp-admin/includes/class-wp-filesystem-ftpext.php index 975a4dd717..3ce8b67996 100644 --- a/src/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/src/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -419,11 +419,22 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { * Checks if a file or directory exists. * * @since 2.5.0 + * @since 6.3.0 Returns false for an empty path. * * @param string $path Path to file or directory. * @return bool Whether $path exists or not. */ public function exists( $path ) { + /* + * Check for empty path. If ftp_nlist() receives an empty path, + * it checks the current working directory and may return true. + * + * See https://core.trac.wordpress.org/ticket/33058. + */ + if ( '' === $path ) { + return false; + } + $list = ftp_nlist( $this->link, $path ); if ( empty( $list ) && $this->is_dir( $path ) ) { diff --git a/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php index da771e4156..1e213ea123 100644 --- a/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -421,11 +421,22 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { * Checks if a file or directory exists. * * @since 2.5.0 + * @since 6.3.0 Returns false for an empty path. * * @param string $path Path to file or directory. * @return bool Whether $path exists or not. */ public function exists( $path ) { + /* + * Check for empty path. If ftp::nlist() receives an empty path, + * it checks the current working directory and may return true. + * + * See https://core.trac.wordpress.org/ticket/33058. + */ + if ( '' === $path ) { + return false; + } + $list = $this->ftp->nlist( $path ); if ( empty( $list ) && $this->is_dir( $path ) ) {