ftp_put(): php_connect_nonb() failed: Operation now in progress (115)

Ok so i have a cron page that I run on my server that does the following

  1. creates backup of the database
  2. puts the created SQL into a .gz archive
  3. uploads the archive to my ftp server (synology NAS DS220j)

But for some reason I’m getting the following errors when it was working just fine. Only thing that has changed is the router, ports have been setup and I can connect to the FTP server, with filezilla iand I can upload and download as normal from it.

The database db_name was successfully stored in the following path root_to_public_html/backup/backup-2023-03-14.sql

Warning: ftp_put(): php_connect_nonb() failed: Operation now in progress (115) in root_to_public_html/backup.php on line 110

Warning: ftp_put(): Type set to I. in root_to_public_html/backup.php on line 110
Error: While uploading backup-2023-03-14.sql.gz to 51.52.230.117.

<?php
//display errors
error_reporting(E_ALL); 
ini_set("display_errors", 1);

$core_path = dirname(__FILE__);
//Enter your database information here and the name of the backup file
$mysqlDatabaseName ="db_name";
$mysqlUserName ="db_user";
$mysqlPassword ="db_pass";
$mysqlHostName ="localhost";
$mysqlExportPath = "{$core_path}/backup/backup-".date('Y-m-d').".sql";

//----------------------------------------------------------------
//local testing
//----------------------------------------------------------------
//$mysqlUserName ="root";
//$mysqlPassword ="";


$conn = new mysqli($mysqlHostName, $mysqlUserName, $mysqlPassword, $mysqlDatabaseName);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

//Please do not change the following points
//Export of the database and output of the status
$output=array();
$command='mysqldump --opt -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' > '.$mysqlExportPath;
exec($command,$output,$worked);
switch($worked){
case 0:
echo 'The database <b>' .$mysqlDatabaseName .'</b> was successfully stored in the following path '.getcwd().$mysqlExportPath .'</b><br>';
    $sql ="INSERT INTO db_backup (backup_date) VALUES ('".date('Y-m-d')."')";
    $resultSql = $conn->query($sql);
break;
case 1:
echo 'An error occurred when exporting <b>' .$mysqlDatabaseName .'</b> zu '.getcwd().'/' .$mysqlExportPath .'</b><br>';
break;
case 2:
echo 'An export error has occurred, please check the following information: <br/><br/><table><tr><td>MySQL Database Name:</td><td><b>' .$mysqlDatabaseName .'</b></td></tr><tr><td>MySQL User Name:</td><td><b>' .$mysqlUserName .'</b></td></tr><tr><td>MySQL Password:</td><td><b>NOTSHOWN</b></td></tr><tr><td>MySQL Host Name:</td><td><b>' .$mysqlHostName .'</b></td></tr></table><br>';
break;
}

//----------------------------------------------------------------
//Set defaults
//----------------------------------------------------------------

set_time_limit(0);
$ftp_count                      = -1;

//----------------------------------------------------------------
//FTP credentials
//----------------------------------------------------------------
//Configure credentials of one or more ftp server to transfer the backup

//FTP 1
$ftp_count++;
$ftp[$ftp_count]['ftps']                = false;
$ftp[$ftp_count]['ftp_server']          = "ftp.server.co.uk";
$ftp[$ftp_count]['ftp_user']            = "user";
$ftp[$ftp_count]['ftp_password']        = "pass";
$ftp[$ftp_count]['ftp_passive_mode']    = true;
$ftp[$ftp_count]['ftp_remote_folder']   = "/";  //e.g. /mysite/backups


//----------------------------------------------------------------
//Interate over all databases
//----------------------------------------------------------------
if (file_exists("{$mysqlExportPath}".".gz")){
    unlink("{$mysqlExportPath}".".gz"); 
}

$mysqlExportPath = "{$core_path}/backup/backup-".date('Y-m-d').".sql";
exec("gzip {$mysqlExportPath}");

$db_item['sql_file'] = "backup-".date('Y-m-d').".sql";


//----------------------------------------------------------------
//FTP transfer: Transfer sql dump to the configured ftp servers
//----------------------------------------------------------------

if($ftp_count >= 0)
{
    foreach($ftp as $ftp_item)
    {
        //Initiate connection
        if($ftp_item['ftps'])
            $connection_id = ftp_ssl_connect($ftp_item['ftp_server']);
        else
            $connection_id = ftp_connect($ftp_item['ftp_server']);

        if(!$connection_id)
            echo "Error: Can't connect to {$ftp_item['ftp_server']}";


        //Login with user and password
        if($connection_id){
            $login_result = ftp_login($connection_id, $ftp_item['ftp_user'], $ftp_item['ftp_password']);
        }

        if(!$login_result)
            echo "Error: Login wrong for {$ftp_item['ftp_server']}";


        //Passive mode?
        ftp_pasv($connection_id, $ftp_item['ftp_passive_mode']);

        //Upload file to ftp
        if (!ftp_put($connection_id, $ftp_item['ftp_remote_folder']."backup-".date('Y-m-d').".sql.gz", $mysqlExportPath.'.gz', FTP_BINARY))
        {
            echo "Error: While uploading {$db_item['sql_file']}.gz to {$ftp_item['ftp_server']}.";
        }

        //Close ftp connection
        ftp_close($connection_id);
    }
}

?>

I’ve had a look through here but all i can see if people advising to use ftp_pasv() which I do as you can see in the code.

ive also tried adding

ftp_set_option($connection_id, FTP_USEPASVADDRESS, false);

before

ftp_pasv($connection_id, $ftp_item['ftp_passive_mode']);

I’m totally baffled as to why it wont work 🙁