What is the function of ftp_rawlist in PHP and how can it be used to retrieve directory information from an FTP server?

The function ftp_rawlist in PHP is used to retrieve a detailed listing of files and directories in a specified directory on an FTP server. This function returns the raw directory listing as an array of strings, which can then be parsed to extract file names, sizes, permissions, and other information. To use ftp_rawlist to retrieve directory information from an FTP server, you need to establish an FTP connection, navigate to the desired directory, and then call ftp_rawlist with the directory path as the argument.

// Connect to FTP server
$ftp_connection = ftp_connect('ftp.example.com');
$login = ftp_login($ftp_connection, 'username', 'password');

// Change to the desired directory
ftp_chdir($ftp_connection, '/path/to/directory');

// Get the raw directory listing
$raw_list = ftp_rawlist($ftp_connection, '.');

// Loop through the raw listing and process the data
foreach ($raw_list as $item) {
    echo $item . "\n";
}

// Close the FTP connection
ftp_close($ftp_connection);