Advertisement
Guest User

Untitled

a guest
May 26th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. <cffunction name="Upload_FTP" access="public" returnType="struct"
  2. hint="Handles the upload functions for FTP method of uploading.">
  3.  
  4. <cfargument name="FTPHost" type="String" required="Yes" hint="The hostname or ip address of the FTP server." default="127.0.0.1">
  5. <cfargument name="FTPPort" type="String" required="Yes" hint="The port of the FTP server." default="2121">
  6. <cfargument name="FTPUser" type="String" required="No" hint="The username to connect to the FTP server." default="">
  7. <cfargument name="FTPPass" type="String" required="No" hint="The password to connect to the FTP server." default="">
  8. <cfargument name="FTPSecure" type="String" required="No" hint="If the invoke should use a Secure connection; Yes|No" default="No">
  9. <cfargument name="FTPTransferMode" type="String" required="No" hint="Transfer Mode; Ascii | Binary | Auto" default="Auto">
  10. <cfargument name="FTPTimeout" type="Numeric" required="No" hint="Timeout in seconds" default="300">
  11. <cfargument name="FTPLocalFile" type="String" required="Yes" hint="The file name to process." default="">
  12. <cfargument name="FTPLocalPath" type="String" required="Yes" hint="The full path to the folder where the file is stored." default="/var/DataVaults/client/temp">
  13. <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">
  14.  
  15. <!--- VAR :: CFSET :: Create structure to return to calling template. --->
  16. <cfset MyUpload = StructNew() />
  17.  
  18. <!--- VAR :: CFSET :: MyUpload.Success --->
  19. <cfset MyUpload.Success = "Yes" />
  20. <cfset MyUpload.Failure = "No" />
  21.  
  22. <!--- CFSETTING :: Set Timeout --->
  23. <cfsetting requesttimeout="#ARGUMENTS.FTPTimeout#" />
  24.  
  25. <cftry>
  26.  
  27. <!--- CFFTP :: Open Connection --->
  28. <cfftp action="open"
  29. connection="objConnection"
  30. server="#ARGUMENTS.FTPHost#"
  31. username="#ARGUMENTS.FTPUser#"
  32. password = "#ARGUMENTS.FTPPass#"
  33. port="#ARGUMENTS.FTPPort#" timeout="#ARGUMENTS.FTPTimeout#"
  34. secure="#ARGUMENTS.FTPSecure#" />
  35.  
  36.  
  37. <!--- CFFTP :: Upload the file to cached connection. --->
  38. <cfftp
  39. action="putfile"
  40. connection="objConnection"
  41. localfile="#ARGUMENTS.FTPLocalPath#/#ARGUMENTS.FTPLocalFile#"
  42. remotefile="#ARGUMENTS.FTPDestinationPath#/#ARGUMENTS.FTPLocalFile#"
  43. transfermode="#ARGUMENTS.FTPTransferMode#"
  44. />
  45.  
  46. <!--- Close the connection. --->
  47. <cfftp action="close" connection="objConnection" />
  48.  
  49. <!--- CFCATCH :: If an error is caught, report to calling script. --->
  50. <cfcatch>
  51. <cfset MyUpload.Failure = "Yes" />
  52. </cfcatch>
  53.  
  54. </cftry>
  55.  
  56. <!--- VAR :: MyUpload.SourceFile :: Sets up the source file in a structure to pass to the calling script. --->
  57. <cfset MyUpload.SourceFile = "#ARGUMENTS.FTPLocalFile#" />
  58.  
  59. <!--- CFRETURN :: Return object to calling template --->
  60. <cfreturn MyUpload />
  61.  
  62. </cffunction>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement