What are the potential pitfalls or security risks when working with FTP in PHP?

One potential security risk when working with FTP in PHP is transmitting sensitive information, such as usernames and passwords, in plain text. To mitigate this risk, it is recommended to use FTPS (FTP over SSL) for secure data transmission.

// Connect to FTP server using FTPS
$ftp_server = 'ftp.example.com';
$ftp_username = 'username';
$ftp_password = 'password';

$conn_id = ftp_ssl_connect($ftp_server);

if ($conn_id) {
    $login_result = ftp_login($conn_id, $ftp_username, $ftp_password);

    if ($login_result) {
        // Successfully connected and logged in
    } else {
        // Failed to login
    }

    ftp_close($conn_id);
} else {
    // Failed to connect
}