Skip to main content
Participating Frequently
May 31, 2023
Question

Does CFthread works when you close the browser window?

  • May 31, 2023
  • 1 reply
  • 145 views

Hi,

I am using CFthread to upload a file to ftp sever, The requirement is to upload the file in background even after the browser window is closed after user start uploading the file. Is is possible with CFthread?

Code that i am using:

<cfif (IsDefined("form.FileContents") && form.FileContents NEQ "")>
<cfthread action="run" name="fileUploadThread">
 
<cfset FileInfo=GetFileInfo("#form.FileContents#")>
 
<cfset fileSizeToUpload = FileInfo.size>
<cfset expectedCheckSum= form.actualCheckSum>
<cfset variables.uploadedFileServerName = "TestUploadFile" & "/" & "#fileName#" />
<!---<cfset fileName =  uploadResult.serverfile/>--->
 
<cfftp connection="session.ftpConn"
action="open"
server="someserverName"
username="someuser"
password="somepassword"
stoponerror="Yes"
timeout="90000">
Did it open connection? <cfoutput>#cfftp.succeeded#</cfoutput><br />
<cfif cfftp.succeeded>
 
<cfftp connection = "session.ftpConn"
action = "PutFile"
localFile="#form.FileContents#"
remoteFile="#variables.uploadedFileServerName#"
stoponerror="Yes"
passive = "Yes"
timeout="90000">
<P>Did it succeed? <CFOUTPUT>#CFFTP.Succeeded#</CFOUTPUT>
</cfif>
 </cfthread>
</cfif>
 
Thanks in advance.
    This topic has been closed for replies.

    1 reply

    Community Expert
    May 31, 2023

    I believe it does continue running, as long as it successfully started and you don't try to join, terminate or sleep the thread in the original page. It might even work in those last three cases. But don't trust me, try it yourself! Use CFFTP to move a big file and see if you get it running to completion after you've closed your browser. This should be an easy test. Let us know what happens!

     

    Note that CFTHREAD isn't going to solve your concurrency problems because threads created with CFTHREAD exist within another fixed thread pool. But it will buy you a little user time, I think.

     

    Dave Watts, Eidolon LLC

    Dave Watts, Eidolon LLC