What are common pitfalls when using PHP ftp functions?

Common pitfalls when using PHP ftp functions include not checking for errors after each ftp function call, not properly handling file permissions and ownership, and not closing the ftp connection after use. To avoid these pitfalls, always check for errors using ftp_error() or ftp_size(), set proper permissions using ftp_chmod(), and close the ftp connection using ftp_close().

// Connect to FTP server
$ftp_conn = ftp_connect('ftp.example.com');

// Login to FTP server
$login = ftp_login($ftp_conn, 'username', 'password');

// Check for errors
if (!$ftp_conn || !$login) {
    die('FTP connection failed');
}

// Set proper permissions
ftp_chmod($ftp_conn, 0644, 'example.txt');

// Close FTP connection
ftp_close($ftp_conn);