Advertisement
Guest User

CPanel Backup Script with FTP Support

a guest
Jul 19th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. <?php
  2.  
  3. // PHP script to allow periodic cPanel backups automatically, optionally to a remote FTP server.
  4. // This script contains passwords. KEEP ACCESS TO THIS FILE SECURE! (place it in your home dir, not /www/)
  5.  
  6. // ********* THE FOLLOWING ITEMS NEED TO BE CONFIGURED *********
  7.  
  8. // Info required for cPanel access
  9. $cpuser = "cpanel_username"; // Username used to login to CPanel
  10. $cppass = 'cpanel_password'; // Password used to login to CPanel
  11. $domain = "www.yourdomain.com.au"; // Domain name where CPanel is run
  12. $skin = "x3"; // Set to cPanel skin you use (script won't work if it doesn't match). Most people run the default x theme
  13.  
  14. // Info required for FTP host
  15. $ftpuser = "FTP_USENAME"; // Username for FTP account
  16. $ftppass = "FTP_PASSWORD"; // Password for FTP account
  17. $ftphost = "FTP_HOSTNAME"; // Full hostname or IP address for FTP host
  18. $ftpmode = "ftp"; // FTP mode ("ftp" for active, "passiveftp" for passive)
  19. $ftpdir = "/location/on/remote/server";
  20. $ftpport = "21";
  21.  
  22. // Notification information
  23. $notifyemail = "backups@yourdomain.com.au"; // Email address to send results
  24.  
  25. // Secure or non-secure mode
  26. $secure = 0; // Set to 1 for SSL (requires SSL support), otherwise will use standard HTTP
  27.  
  28. // Set to 1 to have web page result appear in your cron log
  29. $debug = 0;
  30.  
  31. // *********** NO CONFIGURATION ITEMS BELOW THIS LINE *********
  32.  
  33. if ($secure) {
  34. $url = "ssl://".$domain;
  35. $port = 2083;
  36. } else {
  37. $url = $domain;
  38. $port = 2082;
  39. }
  40.  
  41. $socket = fsockopen($url,$port);
  42. if (!$socket) { echo "Failed to open socket connection... Bailing out!\n"; exit; }
  43.  
  44. // Encode authentication string
  45. $authstr = $cpuser.":".$cppass;
  46. $pass = base64_encode($authstr);
  47.  
  48. $params = "dest=$ftpmode&email=$notifyemail&server=$ftphost&user=$ftpuser&pass=$ftppass&port=$ftpport&rdir=$ftpdir&submit=Generate Backup";
  49.  
  50. // Make POST to cPanel
  51. fputs($socket,"POST /frontend/".$skin."/backup/dofullbackup.html?".$params." HTTP/1.0\r\n");
  52. fputs($socket,"Host: $domain\r\n");
  53. fputs($socket,"Authorization: Basic $pass\r\n");
  54. fputs($socket,"Connection: Close\r\n");
  55. fputs($socket,"\r\n");
  56.  
  57. // Grab response even if we don't do anything with it.
  58. while (!feof($socket)) {
  59. $response = fgets($socket,4096);
  60. if ($debug) echo $response;
  61. }
  62.  
  63. fclose($socket);
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement