Subtotal | $0.00 |
Using the script provided below you will be able to make automatic full cPanel backups of your account.
This backup script includes SSL support. This is not necessary if you run the script on the server for which you are generating the backup, but the SSL support could be important if you are running the script somewhere else to connect to your cPanel hosting account.
<?php
$cpaneluser = 'user'; // cPanel username $cpaneluserpass = 'pass'; // cPanel password. Please note that the cPanel password should not contain special symbols like '&^' to avoid the interruption of the script work $theme = 'jupiter'; // Must match current selected cPanel theme ('jupiter' in the majority of cases) $ftp = true; // Needs to be enabled for the backup to be uploaded to your Namecheap or third-party server; do NOT change the value $ftpserver = 'localhost'; // Must be 'localhost' for current server or custom hostname for remote FTP upload $ftpusername = 'user'; // cPanel/SFTP username. Should be the same as cPanel username for local upload or custom for remote upload $ftppassword = 'pass'; // cPanel/SFTP password. Should be the same as cPanel password for local upload or custom for remote upload $ftpport = '21098'; // SFTP port. Should be 21 for FTP, 22 for SFTP, or your host's specific port in most cases. $ftpdirectory = '/home/'.$cpaneluser.'/backups'; // Directory on FTP server to store backups. MUST EXIST BEFORE BACKUP OR BACKUP PROCESS WILL FAIL. Also, make sure to update the 'cpaneluser' part with your current cPanel username. // Do not edit below this line // === Connection Settings === $domain = 'yourservername'; // Your cPanel server hostname $secure = true; // true = SSL (2083), false = non-SSL (2082) $auth = base64_encode($cpaneluser . ":" . $cpaneluserpass); // Determine connection type if ($secure) { $url = "ssl://" . $domain; $port = 2083; } else { $url = $domain; $port = 2082; } // === Open socket connection === $socket = fsockopen($url, $port); if (!$socket) { exit("? Failed to open socket connection.\n"); } // === Prepare backup parameters === if ($ftp) { $params = "dest=scp&server=$ftpserver&user=$ftpusername&pass=$ftppassword&port=$ftpport&rdir=$ftpdirectory&submit=Generate Backup"; } else { $params = "submit=Generate Backup"; } $content_length = strlen($params); // === Build HTTP request === fputs($socket, "POST /frontend/$theme/backup/dofullbackup.html HTTP/1.0\r\n"); fputs($socket, "Host: $domain\r\n"); fputs($socket, "Authorization: Basic $auth\r\n"); fputs($socket, "Content-Type: application/x-www-form-urlencoded\r\n"); fputs($socket, "Content-Length: $content_length\r\n"); fputs($socket, "Connection: Close\r\n"); fputs($socket, "\r\n"); fputs($socket, $params . "\r\n"); // === Read response (optional: uncomment for debug) === $response = ''; while (!feof($socket)) { $response .= fgets($socket, 4096); } fclose($socket); // Debug output (optional) echo "? Backup request sent. Server response:\n"; // echo $response; // Uncomment if you want to see full HTML response ?>
Need help? We're always here for you.