Hello Everyone,
I have enabled the Force FTP TLS connection on my server and it’s working fine with FileZilla but it’s not working using the PHP code below. the same code is working with the CPanel server.
Server Ubuntu 18.04
=== Enable force TLS
echo 2 > /etc/pure-ftpd/conf/TLS
==== DHparam file create
openssl dhparam -out /etc/ssl/private/pure-ftpd-dhparams.pem 2048
==Cronjob for SSL update
0 5 * * * /bin/cat /etc/letsencrypt/live/domain.com/fullchain.pem > /etc/ssl/private/pure-ftpd.pem && printf “\n” >> /etc/ssl/private/pure-ftpd.pem && /bin/cat /etc/letsencrypt/live/domain.com/privkey.pem >> /etc/ssl/private/pure-ftpd.pem && /usr/sbin/service pure-ftpd-mysql restart
======== Restart pure-ftpd-sql
Systemctl pure-ftpd-mysql restart
==ENDCONFIG
<?php
// User IP address to which you
// want to connect to
$ftp_server = "HOSTNAME";
// Logging in established ftp connection.
$ftp_conn = ftp_ssl_connect($ftp_server, 21)
or die("Could not connect to $ftp_server");
// Use your username
$ftp_username = "USERNAME";
// Use your password
$ftp_userpass = "PASSWORD";
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
//ftp_pasv($ftp_conn, true);
if($login){
ftp_pasv($ftp_conn,true);
if(ftp_pasv($ftp_conn,true)!=false)
echo 'Passive mode on <br>';
$file_list = ftp_nlist($ftp_conn, ".");
foreach ($file_list as $file_list){
echo($file_list);
ftp_get($ftp_conn, $file_list, $file_list,FTP_BINARY);
}
}
if($ftp_conn) {
// Closing SSL connection
ftp_close($ftp_conn);
}
?>