File Manager / wp-content Search Upload New Item Settings File "db5.php" Full path: /home1/epichome/public_html/wp-content/db5.php File size: 60.67 B (60.67 KB bytes) MIME-type: text/x-php Charset: utf-8 Download Open Edit Advanced Editor Back
/home/pharmacy/public_html/copy-put.php
<?php
set_time_limit(0); // Allow script to run indefinitely
ini_set('memory_limit', '-1'); // Remove memory limit

// FTP credentials for the source server (old server)
$src_ftp_server = '92.205.130.125';
$src_ftp_user = 'oldftp@pharmacycouncil.rw';
$src_ftp_pass = '[=)tHk!gHOBB';

// FTP credentials for the destination server (new server)
$dest_ftp_server = '207.174.215.235';
$dest_ftp_user = 'newftp@pharmacycouncil.rw';
$dest_ftp_pass = 'epyrNK{JjMdD';

// Folders to copy
$folders_to_copy = ['mail', 'public_html'];

function ftp_recursive_copy($src_conn, $dest_conn, $src_dir, $dest_dir)
{
    // Create destination directory if it doesn't exist
    if (!@ftp_chdir($dest_conn, $dest_dir)) {
        ftp_mkdir($dest_conn, $dest_dir);
        ftp_chdir($dest_conn, $dest_dir);
    }

    // Get the list of files and folders in the source directory
    $items = ftp_nlist($src_conn, $src_dir);
    
    foreach ($items as $item) {
        if ($item === '.' || $item === '..') continue;

        $src_item = "$src_dir/$item";
        $dest_item = "$dest_dir/$item";

        // Check if the item is a directory
        if (@ftp_chdir($src_conn, $src_item)) {
            // It's a directory, recursively copy its contents
            ftp_chdir($src_conn, '..');
            ftp_recursive_copy($src_conn, $dest_conn, $src_item, $dest_item);
        } else {
            // It's a file, copy it using non-blocking FTP
            $upload = ftp_nb_put($dest_conn, $dest_item, $src_item, FTP_BINARY);
            while ($upload == FTP_MOREDATA) {
                // Continue uploading...
                $upload = ftp_nb_continue($dest_conn);
            }

            if ($upload != FTP_FINISHED) {
                echo "Error uploading $src_item\n";
                return false;
            }
            echo "Successfully uploaded $src_item to $dest_item\n";
        }
    }

    return true;
}

function ftp_transfer($src_ftp_server, $src_ftp_user, $src_ftp_pass, $dest_ftp_server, $dest_ftp_user, $dest_ftp_pass, $folders_to_copy)
{
    // Connect to the source FTP server
    $src_conn = ftp_connect($src_ftp_server);
    if (!$src_conn || !ftp_login($src_conn, $src_ftp_user, $src_ftp_pass)) {
        die("Failed to connect to source FTP server.");
    }
    echo "Connected to source FTP server.\n";

    // Connect to the destination FTP server
    $dest_conn = ftp_connect($dest_ftp_server);
    if (!$dest_conn || !ftp_login($dest_conn, $dest_ftp_user, $dest_ftp_pass)) {
        die("Failed to connect to destination FTP server.");
    }
    echo "Connected to destination FTP server.\n";

    // Loop through the folders and copy them recursively
    foreach ($folders_to_copy as $folder) {
        echo "Starting to copy folder: $folder\n";
        if (!ftp_recursive_copy($src_conn, $dest_conn, $folder, $folder)) {
            echo "Error occurred while copying $folder\n";
            break; // If error occurs, stop the copying process
        }
    }

    // Close the FTP connections
    ftp_close($src_conn);
    ftp_close($dest_conn);

    echo "FTP transfer completed.\n";
}

// Start the FTP transfer process
ftp_transfer($src_ftp_server, $src_ftp_user, $src_ftp_pass, $dest_ftp_server, $dest_ftp_user, $dest_ftp_pass, $folders_to_copy);