Using FTP and WGET to copy and delete files to/from your webspace

If you need to copy files from your web site, or delete and add them, you can use the excellent WGET in conjunction with Windows built in FTP. FTP allows you to call a script to further enhance the functionality.
I recently purchased an IP Camera and wanted to use the detection functionality to copy files up to my free webspace provided by my ISP, that way if I was burgled I know that any movement that the camera detects and records is stored safely in the cloud for a set period of time.
However this presented another problem, my ISP only gives 200mb free so the storage wasn't finite, but I do own a 'nas' device which will allow me to save it there, but what happens if that is stolen, all the recordings would also be gone. So I came up with this solution that I hope you will find useful if you are attempting something similar.
First download the free WGET from here :

http://gnuwin32.sourceforge.net/packages/wget.htm

Unzip the files and copy them to somewhere, for example I will assume it is in c:\temp

Right click in the folder and create a new text document called ftpcopy.txt then rename it to ftpcopy.bat, this will allow windows to execute the file when you double click it.
Right click the file and select 'edit'
Add these commands to the file

wget.exe  -nd --mirror  --ftp-user=YOURWEBSPACEUSERNAME --ftp password=YOURWEBSPACEPASSWORD ftp://YOURFTPSITE

move *.* \\YOURNAS\SOMEFOLDER

So what is happening here? , first of all wget will copy all the files in your webspace to the root of the folder you started it from, then the move command moved them from this folder to a folder on your nas device (not necessary if you just want to leave them where they are).

Next create a second batch file called FTP.bat as you did above
Add these command to the file

ftp -s:script.txt ftp.YOURWEBSPACENAME and save
ftp allows you to call a script to automate things so create another file in the same folder called script.txt and add these commands to it.

user
YOURWEBSPACEUSERNAME
YOURWEBSPACEPASSWORD
prompt a
mdelete *.*
bye

So now you have 2 batch files, ftpcopy.bat and ftp.bat, running the first one copies all the files from your webspace to your local folder, the second deletes all the files from your webspace and clearing up the space.

So how do you automate the process so you have the files removed from your webspace at regular intervals to keep the space clear but keeping a permanent backup on site? .
For this you can use task scheduler built into Vista/Window 7 to automate the whole process, fire up task scheduler and select 'create basic task' in the right pane. Following the wizard, give it a name and description , then select how often you wish the task to run, for my task I selected 'daily', then set it to reoccur every 2 days.
Select 'start a program'  from the next window and point it to the folder where your script is i.e c:\temp\ftp.bat and save it out, you can tick the advanced box and granularly amend any amount of settings to suit your needs, for instance I have mine set to wake the PC up to run the task, (leave the PC in standby for this as it won't wake up from total power off).

So what you have is a script that runs every 2 days, copies everything to your local storage and then deletes all the files.
Your detected files are safe in the cloud for 48 hours if you need to examine them, but you have a local copy for future perusal.

Comments

Popular Posts