What is the best approach to monitoring an FTP directory for new files and sending an email notification using PHP?

One approach to monitoring an FTP directory for new files and sending an email notification using PHP is to use a combination of FTP functions to check for new files and the PHP `mail()` function to send an email notification. You can create a script that connects to the FTP server, checks for new files in the directory, and sends an email notification if new files are found.

<?php
// FTP server credentials
$ftp_server = 'ftp.example.com';
$ftp_username = 'username';
$ftp_password = 'password';

// Connect to FTP server
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);

// FTP directory to monitor
$ftp_dir = '/path/to/ftp/directory';

// Get list of files in the directory
$files = ftp_nlist($conn_id, $ftp_dir);

// Check for new files
if(count($files) > 0) {
    // Send email notification
    $to = 'recipient@example.com';
    $subject = 'New files in FTP directory';
    $message = 'New files have been added to the FTP directory.';
    $headers = 'From: sender@example.com';

    mail($to, $subject, $message, $headers);
}

// Close FTP connection
ftp_close($conn_id);
?>