Created
August 9, 2010 17:42
-
-
Save pmcelhaney/515771 to your computer and use it in GitHub Desktop.
Creates a directory on an FTP server if it doesn't already exist. If necessary, creates intermediate directories as well.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
Creates a directory on an FTP server if it doesn't already exist. If necessary, | |
creates intermediate directories as well. | |
Usage: | |
<cfftp action="open" connection="conn" ... /> | |
<cfset ensureFTPDirectoryExists("/path/to/a/dir", conn)> | |
---> | |
<cffunction name="ensureFTPDirectoryExists"> | |
<cfargument name="dir"/> | |
<cfargument name="connection"/> | |
<cfset var cfftpResult = 0 /> | |
<cfset var exists = false /> | |
<cfset var parentDirectory = "" /> | |
<cftry> | |
<cfftp | |
connection="#connection#" | |
action="existsDir" | |
directory="#dir#" | |
result="cfftpResult"/> | |
<cfset exists = cfftpResult.returnValue> | |
<cfcatch type="Application"> | |
<cfif cfcatch.Message IS "An error occurred during the sFTP EXISTSDIR operation."> | |
<cfset exists = false /> | |
<cfelse> | |
<cfrethrow /> | |
</cfif> | |
</cfcatch> | |
</cftry> | |
<cfif exists eq FALSE> | |
<cfset parentDirectory = reverse(listRest(reverse(dir), '/'))/> | |
<cfset ensureFTPDirectoryExists( parentDirectory , connection)/> | |
<cfftp | |
connection="#connection#" | |
action="createDir" | |
directory="#dir#"/> | |
</cfif> | |
</cffunction> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks its helpful but is it the wrong way to create directory or its safe to use??