I mentioned in my previous post with the same title that I used a renaming function to check if the file was finished and unlocked by the FTP transfer, so I could work with it. Well, after several tests using the renaming test, I was still getting lock up errors and my process was stopping.
After some research, I realized that our FTP server (WS_FTP) did not lock the file when writing to it, so I was able to rename it, and it would continue to upload to the same renamed file. Even when I moved the renamed file to a work directory, the file size was still being increased. So none of my test functions would work.
Instead of changing the FTP server settings – it is an old one installed in 2002 – I decided to install Filezilla Server. Wonderful, it locks the file and my test function now works.
Here is an updated checkFile function, it renames the file for work if it is unlocked.
<cffunction name="checkFile" access="remote" output="false" returntype="Any">
<cfargument name="filePath" type="string" required="true" hint="full physical path" />
<cfargument name="preStr" type="string" required="false" default="work-" />
<cfset result = structNew() />
<cfset jFile = createobject("java", "java.io.File").init(arguments.filePath) />
<cfset newFilePath = reverse(listRest(reverse(arguments.filePath), "\")) & "\" & arguments.preStr & listLast(arguments.filePath, "\") />
<cffile action="rename" source="#arguments.filePath#" destination="#newFilePath#">
<cfset result.status = true />
<cfset result.content = newFilePath />
<cfset result.status = false />
<cfset result.content = "File #listLast(arguments.filePath, '\')# in use..." />
<cfreturn result />
Here is how you call the function:
<cfdirectory name="qDir" action="list" directory="#expandPath('data/')#" filter="*.zip" />
<cfset filePath = qDir.directory & "\" & qDir.name />
<cfset result = checkFile(filePath) />
<!--- status is true: display message and process the file --->
<cfset processTheFile(result.content) />