What are potential pitfalls to avoid when working with FTP connections in PHP scripts?

One potential pitfall to avoid when working with FTP connections in PHP scripts is not properly handling errors or exceptions that may occur during the connection process. It is important to include error handling mechanisms to gracefully handle any issues that may arise, such as connection timeouts or authentication failures.

// Connect to FTP server with error handling
$ftp_server = 'ftp.example.com';
$ftp_username = 'username';
$ftp_password = 'password';

$conn_id = ftp_connect($ftp_server);
if (!$conn_id) {
    die('Failed to connect to FTP server');
}

$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
if (!$login_result) {
    die('Failed to login to FTP server');
}