Category Archives: Programming

FTP Folder Copy/Move with Date Time Batch Script

I decomissioned my DNS-323 NAS which was setup to automatically copy scanned pdf’s off my Brother MFC-440CN Scanner. This meant I needed to re-write my scanning copy shell script to run as a batch script on my main computer.

Re-writing the script was harder than I anticipated. The command line ftp client on windows expects you to know the names of each file. It does however have the ability to run a script file full of ftp commands. So the solution to getting the script working was:

  1. Run a temporary script for ftp to get a file listing
  2. Run another temp script for ftp that fetchs and deletes each file in the file listing.
  3. Cleanup/delete temporary scripts/files

What it does:

Moves files from the specified ftp directory to the specified local directory prepended with the date and time.


Create a .bat file with the script below. Then set the parameters at the beginnng of the script as follows:

  • set server= the ip address of your ftp server (in my case my scanner)
  • set fetch_directory= the directory on the ftp server to copy/move files from
  • set target_dir = the directory on the local computer to copy/move the files to

The Script

@echo off

:: downloads then deletes ftp files from the given location

set server=
:: no trailing / on fetch dir path
set fetch_directory=/BROTHER
:: no trailing \ on target dir path
set target_dir=c:\Users\myusername\Docs\Scan
set temp_script_file=ftp_script.txt
set temp_dir_list=ftp_file_list.txt

:: create temp file with ftp script to output file list
echo open %server% > %temp_script_file%
echo. >> %temp_script_file%
echo mdir %fetch_directory% %temp_dir_list% >> %temp_script_file%
echo y >> %temp_script_file%
echo bye >> %temp_script_file%

:: now run the script with ftp
ftp -s:%temp_script_file%

:: now we have a list of the files in the ftp directory

:: now make a script from the file listing to copy each file.
echo open %server% > %temp_script_file%
echo. >> %temp_script_file%
echo lcd %target_dir%  >> %temp_script_file%
:: copy each file to a dated file locally
for /F "tokens=9 skip=3" %%i in (%temp_dir_list%) do (
SET get_file=%%i
echo binary >> %temp_script_file%
echo get %fetch_directory%/!get_file:~0,-1!  "%target_dir%\%date:~10,4%-%date:~7,2%-%date:~4,2% %time:~0,2%.%time:~3,2%.%time:~6,2%.%time:~9,2% !get_file:~0,-1!" >> %temp_script_file%
echo delete %fetch_directory%/!get_file:~0,-1!  >> %temp_script_file%
echo bye >> %temp_script_file%

:: now run the new script
ftp -s:%temp_script_file%

::remove temporary script files
del %temp_dir_list%
del %temp_script_file%

Acronym Builder

Enter words for acronym seperated by spaces:



A free feedback / help button for your website with HelpMe.js

free feedback link screenshot

If you use a service like or they will charge you upwards of $20 a month for the privelage of having a ‘feedback’ tab/button on the side of your website and the ability to accept feedback. Granted they give you lots of features to manage and track your feedback, but if you just have a small site it is an unjustifiable cost.

Thats why I made a free JavaScript called ‘HelpMe’ that you can include in you web pages that displays a ‘help’ tab/button on the side of your web page and links to a Google Docs Form or just creates a pre-formated email for your user to send to you.

Setup is easy:

  1. Download and unzip it.
  2. Open helpme.js with a text editor and fill in the values under the //Settings sectionhelpme.js settings setup screenshot
    1. If you are using a Google Docs Form just place the url for your form in the setting b.googleFormUrl .
    2. If you are using email then enter your email, subject and body in place of the examples and make sure that b.googleFormUrl is set to “” (blank).
  3. Save helpme.js
  4. Upload the helpme folder including ‘helpme.js’ and ‘helpme.png’ to the root of your website.
  5. Place the tag  <script type=”text/javascript” src=”/helpme/helpme.js” /> in the head or body of the pages where you want the button to appear.

Thats it, Enjoy!


Easily reply to your google form responses

 Inserting 'Reply' link formula

Google Docs lets you really easily create web forms, which are great for surveys, site feedback and more (and importantly free). However responding to submitted forms can be a little more difficult as your data just ends up in a big spreadsheet.

Luckily you can use a spreadsheet formula to easily create a ‘Reply’ email link for each submitted form using these steps:

  1. Create a google form. Make sure that you create a field on your form to collect an email address.
  2. Open your forms spreadsheet and select the very top cell of an empty column to place the ‘Reply’ links in.
  3. Insert =HYPERLINK(“mailto:”&TRIM(B1),”Reply”) into the cell (bold text only) replacing the text ‘B1’ with the top cell of the column that contains the email addresses from your form.
  4. Click the letter at the top of the column to select all of that column’s cells and press CTRL + D to fill the formula down to all the cells.
  5. Go to the view menu and select ‘List View’ to make the links easily clickable.


Unfortunately you cannot automatically populate the subject and body of the email. Whilst google spreadsheet supports ‘mailto:’ urls it doesn’t support the ‘?subject=’ and ‘&body=’ extensions.

Reply links for google form responses in list view

A Simple Javascript Namespace Manager

Chris Pietschmann has a great article on a simple namespace manager. He states that if your using an AJAX framework you should obviously use the namespace management that it provides. However his code is perfect for my situation where I don’t have my AJAX framework loaded yet but do need my namespaces defined.

Anyway the reason for the post is that I refactored Chris’s code into a smaller recursive function:


/// Create the Namespace Manager that we'll use
///to make creating namespaces a little easier.
if (typeof Namespace == 'undefined') var Namespace = {};
if (!Namespace.Manager) Namespace.Manager = {};

Namespace.Manager = {
Register: function(ns) {
if (ns.length > 0) {
myBaseNs = ns.substring(0, ns.lastIndexOf('.'));
eval("if(!window." + ns + ") window." + ns + " ={};");

Compress all javascript files in a folder


I was looking into compressing JavaScript files and came across this JavaScript compressor by Dean Edwards. On the site he offers a .NET port by Jesse Hansen, which I have just ‘hacked’ to recursively duplicate a directory with the .js files compressed. I say ‘hacked’ as it was a bit of a rush job, but it seems to work. It also lets you put in a ‘header’ which allows you to put an author/copyright notice at the top of each of the compressed files. The dupicate folder is created in the same location as the orginal and named the same as the original with ‘_packed’ appended.


The original code is covered by a ‘GNU LGPL’ licence, so I’m posting my modifications here for anyone who might need or want them. I made my changes in Visual Studio 2008 so if you want to open the project you will need a copy (the free/express version should work fine). You will also need the .NET framework installed, I think the installer will prompt you to download it if you don’t already have it installed.


Download (source & installer):




How to create a Role or User based on an existing Role or User in MSSQL 2005

I found myself needing to create new sql users and roles with permissions from existing users in the database in order to tidy up some database logins. After an hour or so of searching I still hadn’t found anything like what I was looking for so I asked on experts exchange.

One of the users posted this great sql script from Vyas website which creates a SQL script to set the permissions on a user or role to that of an existing user or role.

All you need to generate a change script is set the @OldUser and @NewUser parameters to those in your database and run the script. The great thing then is that you can edit the script that this script generates (eg remove some grant or denys to certain objects) before you execute it on your database.