A Batch File that Uploads/Backs-up to FTP
Friday, February 15, 2008This is something really simple but I find it really useful for a number of tasks.
it's basically a batch file that connects to any FTP webspace and uploads files. The good thing about it is that you can give clients a means of uploading a file by just double-clicking. You can also schedule the batch file to run using Task Scheduler in Windows.
I have set it up on one of my dedicated servers as a Scheduled Task so that first a command-line zip utility zips my clients entire website, I then use this Scheduled batch file to upload/backup to webspace hosted with the same company, which means the webspace is on the same network and therefore the upload takes a 30 seconds for a 200Mb backup, and the files are on a completely different server - Great!
Batch file contents (FtpUpload.bat)
This is the file that you can schedule, it merely contains the location of the ftp instructions file that you wisdh to run (make sure you change the file path accordingly), and the ftp hostname.
ftp -s:
C:\PathofFiles\FtpAccountAndFiles.ftp
yourhostname.com
Ftp instructions file contents (FtpAccountAndFiles.ftp)
This is the file that contains your ftp username, password and the files you wish to upload, in this case an example file (stored in the same directory as the batch file).
yourftpusername
yourftppassword
put ExampleFile.txt
quit
Hey presto! There you go, a free upload or backup solution!
Here are the files (Zip, 1Kb)
Now to use it as a backup solution you will need compression software to make it easier! - my solution...
First you will have to download and install WinRar trial (version 3.71 at time of writing) from http://www.rarlabs.com/download.htm - This version hasn't changed for ages (years!?), if unregistered all you get is a small nag screen (no functionality is taken away). I think WinRar is the best archiving software availible! - Why? because of the simple context menu (right-click) operations for zipping and un-zipping and also many powerful yet easy to use functions such as the self-extracting executable setup and of course the command-line archiving functionality of which we are going to use..
When we have WinRar installed, the below code, when added to the top of your batch file will compress your files (into one file) so you can upload it with the above batch script.
c:\Program Files\WinRar\winrar a -r0 -x*.dll -x*.rws -x*.rar "D:\BackupsForUpload\YourWebsite.rar" "D:\home\yourwebsite.co.uk\htdocs\*.*"
(Note: the above is all on one line if it appears differently on the page)
Basically the aboveline is telling WinRar to create an archive and add all the files from the mentioned location to the rar file. Voila!
Comments (3)
Thursday, April 10, 2008 18:52 | #
u got the same name as me
Thursday, April 29, 2010 15:54 | #
I love the picture on top - very nice. Have you tried thi
s script for uploading an entire directory structure ? href="http://www.biterscripting.com/helppages/SS_FTPUpload.
html" title="http://www.biterscripting.com/helppages/SS_FTPU
pload.html" target="_blank">http://www.biterscripting.com/he
lppages/SS_FTPUpload.html It creates subdirectories
when needed.
Tuesday, June 22, 2010 07:33 | #
Buildings are expensive and not everybody is able to buy it.
Nevertheless, personal loans was invented to aid people in
such kind of cases.