PHP FTP over Explicit TLS not working

,

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);
}
?>

@usman bhai and @community please help

Hello Everyone,
I have resolved the issue after investing 7-8 hours and below is the solution and reason of the issue.
The issue was occurring due to the flag require_ssl_reuse. A lot of FTP clients have trouble dealing with it.

Solution
If a Ubuntu or Debian server is using Pure-FTPD then they must enable echo ‘yes’ > BrokenClientsCompatibility
If a cPanel server is using Pure-FTPD then they must enable —> Broken Clients Compatibility=yes

Hope this will help someone else.

This topic was automatically closed 3 hours after the last reply. New replies are no longer allowed.