Are there best practices for establishing a secure FTP connection using PHP and cURL?
Establishing a secure FTP connection using PHP and cURL involves setting the appropriate options to ensure secure data transfer. This includes specifying the FTPS protocol, enabling SSL/TLS encryption, and verifying the server's certificate. By following best practices, you can create a secure connection for transferring files over FTP.
$ftp_server = 'ftp.example.com';
$ftp_user = 'username';
$ftp_pass = 'password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "ftp://$ftp_server");
curl_setopt($ch, CURLOPT_USERPWD, "$ftp_user:$ftp_pass");
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($ch);
if ($result === false) {
echo "Error: " . curl_error($ch);
} else {
echo "File uploaded successfully.";
}
curl_close($ch);