ColdFusion: compare local files with remote FTP files

Written on 10 October 2011, 04:59pm

Tagged with: ,

What do you do when you discover that the production version of an application is not the same as the development version? (ignore the bigger problems of application development workflow)
You identify the files in question, yes. And what do you identity them when the application contains thousands of source files?
Of course, you make a script.

<cfsetting requesttimeout="300" showdebugoutput="no" />
<cfset initialDir = ExpandPath( '../' )> 
<!--- script is in a sub-folder of the app --->
<cfset total = 0> <!--- total changed files --->
<cfset subTotal = 0> <!--- actual changed files, see below --->
<cfset localRoot = "C:\your\local\app\root" />
<cfset remoteRoot = "/your/remote/root" />
<cfset tmpFile = "/this/is/just/a/temp/file" />

<cfset tick = GetTickCount()>

<!--- get list of ALL local files, recursively --->
<cfdirectory action="list" 

<!--- make the FTP connection --->
<cfftp connection = "ftpConnection" 
    username = "*********"
    password = "*********"
    server = "********"    
    action = "open" 
    stopOnError = "Yes"> 
<cfif cfftp.succeeded EQ false>
    ERROR - FTP open connection failed!

<!--- call the recursive function for the first time --->
<cfset compareFiles(remoteRoot) />

<!--- close the FTP connection --->
<cfftp connection = "ftpConnection"
    action = "close"
    stopOnError = "Yes">
<cfif cfftp.succeeded EQ false>
    ERROR - FTP close connection failed!<cfabort>

<cfset tock = GetTickCount()>
<cfset time = round((tock-tick)/1000)>
<cfoutput><hr />#subTotal#/#total# files, #time# seconds</cfoutput>

This is the skeleton. The business logic happens in the function below: