CFFTP action EXISTSDIR bug

January 9, 2010 · 3 Comment s

<cfftp action="EXISTSDIR" connection="myConnection"
        directory="/home/andy.allan/new_folder" 
        port="22" fingerprint="goes_here" secure="true">

The above Code throws the following error should the directory not exist:

An error occured during the sFTP EXISTSDIR operation.

According to the documentation, any code with the attribute action="EXISTSDIR" should provide a return value accessible via cfftp.returnValue and this value should be true or false.

The way around this is to use some error handling and to catch the exception by doing the following:

<cfftp action="EXISTSDIR" connection="myConnection"
        directory="/home/andy.alla/new_folder/" 
        port="22" fingerprint="goes_here" secure="true">
       
       
        <cfcatch type="any">
            <cfif cfcatch.action IS "EXISTSDIR" AND cfcatch.Message IS "An error occurred during the sFTP EXISTSDIR operation.">
                <cfftp action="CREATEDIR" connection="myConnection"  
        directory="/home/andy.allan/new_folder"  port="22" fingerprint="goes_here" secure="true">
            <cfelse>
            <cfdump var="#cfcatch#" />
            <cfabort>
            </cfif>
        </cfcatch>
</cftry>

Tags: ColdFusion

3 response s so far ↓

  • 1 Patrick McElhaney // Aug 9, 2010 at 5:56 PM

    Thanks! I added your code to a function I had created earlier called ensureFTPDirectoryExists().

    http://gist.github.com/515771
  • 2 Chris Williams // Mar 15, 2011 at 4:30 PM

    I have noticed that this does not always return an error. I was working off one FTP site, where it worked fine - but when I moved to a different FTP site, it failed. Could it be something to do with the FTP site settings/permissions? I was also able to use listdir too - so perhaps this could be used instead of cftry?
  • 3 Chris Williams // Mar 15, 2011 at 4:31 PM

    Ah - I have just checked and I moved from a normal FTP site to an SFTP site. That would explain the differences!

Leave a Comment

Leave this field empty: