What are the potential security risks associated with using ftp_connect() in PHP scripts?

The potential security risks associated with using ftp_connect() in PHP scripts include transmitting sensitive data, such as usernames and passwords, in plain text over the network, making them susceptible to interception. To mitigate this risk, it is recommended to use FTPS (FTP over SSL) or SFTP (SSH File Transfer Protocol) for secure data transmission.

// Connect using FTPS (FTP over SSL)
$ftp_server = 'ftp.example.com';
$ftp_user = 'username';
$ftp_pass = 'password';
$ftp_connection = ftp_ssl_connect($ftp_server);
$login_result = ftp_login($ftp_connection, $ftp_user, $ftp_pass);

if (!$ftp_connection || !$login_result) {
    die('FTP connection failed');
}