Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <cffunction name="Upload_FTP" access="public" returnType="struct"
- hint="Handles the upload functions for FTP method of uploading.">
- <cfargument name="FTPHost" type="String" required="Yes" hint="The hostname or ip address of the FTP server." default="127.0.0.1">
- <cfargument name="FTPPort" type="String" required="Yes" hint="The port of the FTP server." default="2121">
- <cfargument name="FTPUser" type="String" required="No" hint="The username to connect to the FTP server." default="">
- <cfargument name="FTPPass" type="String" required="No" hint="The password to connect to the FTP server." default="">
- <cfargument name="FTPSecure" type="String" required="No" hint="If the invoke should use a Secure connection; Yes|No" default="No">
- <cfargument name="FTPTransferMode" type="String" required="No" hint="Transfer Mode; Ascii | Binary | Auto" default="Auto">
- <cfargument name="FTPTimeout" type="Numeric" required="No" hint="Timeout in seconds" default="300">
- <cfargument name="FTPLocalFile" type="String" required="Yes" hint="The file name to process." default="">
- <cfargument name="FTPLocalPath" type="String" required="Yes" hint="The full path to the folder where the file is stored." default="/var/DataVaults/client/temp">
- <cfargument name="FTPDestinationPath" type="String" required="Yes" hint="The relative path from the user home directory to the location the file should be uploaded to." default="DataVault/temp">
- <!--- VAR :: CFSET :: Create structure to return to calling template. --->
- <cfset MyUpload = StructNew() />
- <!--- VAR :: CFSET :: MyUpload.Success --->
- <cfset MyUpload.Success = "Yes" />
- <cfset MyUpload.Failure = "No" />
- <!--- CFSETTING :: Set Timeout --->
- <cfsetting requesttimeout="#ARGUMENTS.FTPTimeout#" />
- <cftry>
- <!--- CFFTP :: Open Connection --->
- <cfftp action="open"
- connection="objConnection"
- server="#ARGUMENTS.FTPHost#"
- username="#ARGUMENTS.FTPUser#"
- password = "#ARGUMENTS.FTPPass#"
- port="#ARGUMENTS.FTPPort#" timeout="#ARGUMENTS.FTPTimeout#"
- secure="#ARGUMENTS.FTPSecure#" />
- <!--- CFFTP :: Upload the file to cached connection. --->
- <cfftp
- action="putfile"
- connection="objConnection"
- localfile="#ARGUMENTS.FTPLocalPath#/#ARGUMENTS.FTPLocalFile#"
- remotefile="#ARGUMENTS.FTPDestinationPath#/#ARGUMENTS.FTPLocalFile#"
- transfermode="#ARGUMENTS.FTPTransferMode#"
- />
- <!--- Close the connection. --->
- <cfftp action="close" connection="objConnection" />
- <!--- CFCATCH :: If an error is caught, report to calling script. --->
- <cfcatch>
- <cfset MyUpload.Failure = "Yes" />
- </cfcatch>
- </cftry>
- <!--- VAR :: MyUpload.SourceFile :: Sets up the source file in a structure to pass to the calling script. --->
- <cfset MyUpload.SourceFile = "#ARGUMENTS.FTPLocalFile#" />
- <!--- CFRETURN :: Return object to calling template --->
- <cfreturn MyUpload />
- </cffunction>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement