ColdFusion 9.0 Resources |
cfftp: Connection: file and directory operationsSyntax<cfftp action = "action" ASCIIExtensionList = "extensions" connection = "connection name" directory = "directory name" existing = "file or directory name" failIfExists = "yes|no" item = "directory or file" localFile = "filename" name = "query name" new = "file or directory name" passive = "yes|no" password = "password" proxyServer = "proxy server" remoteFile = "filename" result = "result name" server = "server" timeout = "time-out in seconds" transferMode = "ASCII FTP|Binary FTP|Auto FTP" username = "name"> Note: You
can specify this tag’s attributes in an attributeCollection attribute
whose value is a structure. Specify the structure name in the attributeCollection attribute
and use the tag’s attribute names as structure keys.
Attributes
UsageIf you use connection caching to an active FTP connection, you do not have to respecify the username, password, or server connection attributes. Changing a cached connection, such as changing retryCount or timeout values, might require reestablishing the connection. If action = "listDir", the attributes column returns directory or normal. Other platform-specific values, such as hidden and system, are no longer supported. If action = "listDir", a mode column is returned. The column contains an octal string representation of UNIX permissions; for example, "777." The cfftp.returnValue variable provides the return value for these actions:
For more information, see the Developing ColdFusion Applications. localFile attributeUse the following syntax to specify an in-memory file, which is not written to disk, as the local file. In-memory files speed processing of transient data. ram:///filepath The filepath can include directories, for example ram:///petStore/images/poodle.jpg. Create the directories in the path before you specify the file. For more information on using in-memory files, see Optimizing transient files in the Developing ColdFusion Applications. Action (cfftp.ReturnValue variable)The results of an action determine the value of the returnValue variable, as the following table shows:
To access the returnValue variable, you must prefix it with either cfftp or the value specified by the result attribute, if it is set. The result attribute provides a way for cfftp calls from multiple pages, possibly at the same time, to avoid overwriting the results of one with another. If you set the result attribute to myResult, for example, you would access the returnVariable variable as myResult.returnVariable. Otherwise, you would access it as cfftp.returnVariable. ExampleThe following example opens a connection and gets a file that lists file or directory name, path, URL, length, and modification date: <p>Open a connection <cfftp connection = "myConnection" username = "myUserName" password = "myUserName@allaire.com" server = "ftp.allaire.com" action = "open" stopOnError = "Yes"> <p>Did it succeed? <cfoutput>#cfftp.succeeded#</cfoutput> <cfftp connection = "myConnection" action = "LISTDIR" stopOnError = "Yes" name = "ListDirs" directory = "/"> <p>FTP Directory Listing:<br> <cftable query = "ListDirs" HTMLTable = "Yes" colHeaders = "Yes"> <cfcol header = "<b>Name</b>" text = "#name#"> <cfcol header = "<b>Path</b>" text = "#path#"> <cfcol header = "<b>URL</b>" text = "#url#"> <cfcol header = "<b>Length</b>" text = "#length#"> <cfcol header = "<b>LastModified</b>" text = "#DateFormat(lastmodified)#"> <cfcol header = "<b>IsDirectory</b>" text = "#isdirectory#"> </cftable> <p>Move Image File to Remote Server:<br></p> <!--- The image will be put into the root directory of the FTP server unless otherwise noted, i.e., remoteFile = "somewhere_put.jpg" vs remoteFile = "/support/somewhere_put.jpg" ---> <cfftp connection = "myConnection" action = "putFile" name = "uploadFile" transferMode = "binary" localFile = "C:\files\upload\somewhere.jpg" remoteFile = "somewhere_put.jpg"> <p>Did it succeed? <cfoutput>#cfftp.succeeded#</cfoutput> <p>Close the connection: <cfftp connection = "myConnection" action = "close" stopOnError = "Yes"> <p>Did it succeed? <cfoutput>#cfftp.succeeded#</cfoutput> |