Coolest Guides on the Planet

coolest guides on the planet

Coolest Guides On The Planet

  • Home
  • macOS
  • WebDev
  • All Posts
  • Contact

Script an FTP connection to login and download your cPanel backup

June 26, 2011 1 Comment

To create a script that can automatically log in to your website and download a cPanel backup, a couple of things need to be done on the OS X client computer. Its worth remembering that a backup on a website still really needs a copy off it.

First, if you need to, see an earlier post describing how to back up the website via cPanel.

{a} Create a “.netrc” file in your home directory and give it three properties; machine, login and password – so the format will be:

machine yourdomain.com
login yourftplogin
password yourftppassword

 

Can also be formatted as:

machine yourdomain.com login yourftplogin password yourftppassword

 

If you have multiple websites you can repeat them straight after the sequence. Save the file as .netrc and file it in your home directory root level. This file should only have permissions so that only you can read it – so a “chmod 600 .netrc” should do the trick. Now when you execute the ftp command in the command line to your website no password should be prompted for:

[~] ftp yourdomain.com

 

An interactive ftp session will occur but you shouldn’t be prompted for a password, quit the session by typing quit.

{b} Create a directory on your local machine where the backups will be copied to such as :

/Users/username/Desktop/websitebackup/

{c} Now we are able to write a script that can download the cPanel backup or any other file for that matter. If a backup download is required a simple script would be:

ftp <<**
open yourdomain.com
bell
prompt
lcd /Users/username/Desktop/websitebackup/
cd /backups/daily/
mget *
quit

 

Notes on the script:

So the script has ftp commands, your info needs to change as marked in red, the “lcd” is the local back up directory where the back ups will be copied to, the “cd” is the remote directory where the backups will be copied from, the “mget” will copy all the files in the remote directory as denoted by the “*” this can be changed by using the literal name of the backup, but since the back up name chnages according to the date either a “*” or a “backup*” will be ok, obviously depending on what the backup name is 🙂 .

Save the file as a script; “backup.sh” and save to a location that you can run as a command or as known as ‘somewhere in your path’, for example save it in:

/usr/sbin/backup.sh

{d} The backup script will need to have certain ownership and permissions to run as a script, run the next 2 commands as root to complete this:

sudo chown root:wheel /usr/sbin/backup.sh
sudo chmod  755 /usr/sbin/backup.sh

 

The resulting permissions should look like:

-rwxr-xr-x@   1 root   wheel       221B Jun 26 15:13 backup.sh

 

Quit and relaunch the Terminal and now run the command “backup.sh” and you should get a interactive ftp session that will connect, download your files and then disconnect the session on completion. You can run this command whenever you like and to fully automate the process schedule it as a cron or launch agent  job.

Cats: Open Source Tags: automate, backup, cpanel, ftp, OSX, script, shell, terminal

Tags

3gs 10.6 apache backup baseband boot clean urls cpanel css curl custom database drupal el capitan git Google image instadmg ios iphone jailbreak keys lion mac macos mojave macos sierra menu mysql OSX panda php phpmyadmin private public redirect redsn0w remote rsa SEO shell ssh terminal unstoppables upgrade urls

Donate a Beer to the Coolest Guides

Get Beaver Builder Now!

Discuss

3gs 10.6 apache backup baseband boot clean urls cpanel css curl custom database drupal el capitan git Google image instadmg ios iphone jailbreak keys lion mac macos mojave macos sierra menu mysql OSX panda php phpmyadmin private public redirect redsn0w remote rsa SEO shell ssh terminal unstoppables upgrade urls
Get DesktopServer

Lynda

Lynda.com Online Training Videos

TreeHouse

smlinks

Learn WordPress
osx-modify-shell-path

How to Add to the Shell Path in macOS Big Sur and Catalina using Terminal

October 19, 2019

virtual-hosts osx 10.10 yosemite

Set up Virtual Hosts on macOS Catalina 10.15 in Apache

October 19, 2019

Installing Homebrew on macOS Catalina 10.15, Package Manager for Linux Apps

October 18, 2019

Where is the bash shell in macos Catalina?

October 12, 2019

Refine your search

  • All
  • Modules
  • Themes
  • Documentation
  • Forums & Issues
  • Groups

RSS ars technica

  • Musi says evidence shows Apple conspired with music industry on App Store ban
  • Trump threatens Apple with 25% tariff to force iPhone manufacturing into US
  • I helped a lost dog’s AirTag ping its owner: An ode to replaceable batteries
  • Apple legend Jony Ive takes control of OpenAI’s design future
  • Epic goes to court to force Fortnite back on US iOS

RSS mac surfer

  • Tot is new text editor for Mac, iPhone, and iPad focused on constraints and ease of use
  • TiPbITS: Google Drive Sorting Can Hide New Documents
  • How to take a screenshot on a MacBook Pro
  • How To Create Simple Animation With Mac Keynote
  • Last Week on My Mac: Virus pandemics

Donate

Copyright © 2025· Neil Gee - All Rights Reserved - Hosted by Runcloud

Copyright © 2025 · gee on Genesis Framework · WordPress · Log in