What potential pitfalls should be considered when using FTP functions in PHP, such as error handling and resource types?

When using FTP functions in PHP, it is essential to handle errors properly to ensure the stability and security of your application. Additionally, it is crucial to manage resource types correctly to prevent memory leaks and optimize performance.

// Example of proper error handling when using FTP functions in PHP
$conn = ftp_connect('ftp.example.com');
if (!$conn) {
    die('Failed to connect to FTP server');
}

$login = ftp_login($conn, 'username', 'password');
if (!$login) {
    die('Failed to login to FTP server');
}

// Properly close the FTP connection when done
ftp_close($conn);