WP_Filesystem_ftpsockets::exists( string $path ): bool

In this article

Checks if a file or directory exists.

Parameters

$pathstringrequired
Path to file or directory.

Return

bool Whether $path exists or not.

Source

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 ) ) {
		return true; // File is an empty directory.
	}

	return ! empty( $list ); // Empty list = no file, so invert.
	// Return $this->ftp->is_exists($file); has issues with ABOR+426 responses on the ncFTPd server.
}

Changelog

VersionDescription
6.3.0Returns false for an empty path.
2.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.