Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In coldFusion CFFTP, existsDir generate error if dir doesn't exist

I am using existsDir to check if a folder exists or not.

<cfftp action="existsDir" 
       connection="FTP" 
       directory="/Download/Test">
#cfftp.returnvalue#

If the folder exists, then everything works fine. The returnvalue is "yes". If the folder doesn't exist, then the existsDir action fails with the following error:

An error occurred during the sFTP existsDir operation. The system cannot find the path /Download/Test 

The whole point of this action is to determine whether a folder exists. Yet it is causing an error if it doesn't exist. Am I missing something?

I can add try and catch around this whole statement (i am going add it anyway just to be safe), but that would make this existDir pointless.

like image 383
help Avatar asked Nov 01 '22 17:11

help


1 Answers

I experienced this also. Seems to be a bug alright even in CF 2016 (which we just migrated to). I got around it by setting stoponerror="No" during the cfftp action="existsDir" usage like this;

<cfftp action="existsDir"
       connection="ftp_connection"
       directory="#remote_path#"
       stoponerror="No">

You can then just check if it 'succeeded' and create the Dir if necessary;

<cfif cfftp.succeeded NEQ "YES">

    <!--- Create directory --->
    <cfftp action="createDir"
         connection="ftp_connection"
         directory="#remote_path#"
         stoponerror="No">
</cfif>
like image 116
IanOSullivan Avatar answered Nov 15 '22 10:11

IanOSullivan