Adobe COLDFUSION 9 Manual page 1247

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using External Resources
4
Save the file as ftp_connect.cfm in the myapps directory under your web_root and view it in the web browser.
Reviewing the code
The following table describes the code and its function:
Code
<cfftp connection="Myftp" server="MyServer"
username="MyUserName" password="MyPassword"
action="Open" stoponerror="Yes">
<cfftp connection=Myftp action="GetCurrentDir"
stoponerror="Yes">
<cfoutput>
The current directory is: #cfftp.returnvalue#<p>
</cfoutput>
<cfftp connection=Myftp action="ListDir"
directory="#cfftp.returnvalue#" name="dirlist"
stoponerror="Yes">
<cfftp action="close" connection="Myftp">
<p>Did the connection close successfully?
<cfoutput>#cfftp.succeeded#</cfoutput></p>
<cftable query="dirlist" colheaders="yes"
htmltable>
<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>
After you establish a connection with
either you or the server closes the connection. When you access an already-active FTP connection, you need not
respecify the user name, password, or server. In this case, make sure that when you use frames, only one frame uses
the connection object.
Note: For a single simple FTP operation, such as GetFile or PutFile, you need not establish a connection. Specify all the
necessary login information, including the server and any login and password, in the single
Caching connections across multiple pages
The FTP connection established by the cfftp tag is maintained only in the current page unless you explicitly assign the
connection to a variable with Application or Session scope.
Assigning a
connection to an application variable could cause problems, since multiple users could access the
cfftp
same connection object at the same time. Creating a session variable for a
because the connection is available to only one client and does not last past the end of the session.
Description
Open an FTP connection to the MyServer server and log on as
MyUserName. If an error occurs, stop processing and display an error.
You can use this connection in other
Myftp connection.
Use the Myftp connection to get the name of the current directory;
stop processing if an error occurs.
Display the current directory.
Use the Myftp connection to get a directory listing. Use the value
returned by the last
connection) to specify the directory to list. Save the results in a
variable named dirlist (a query object). Stop processing if an error
occurs.
Close the connection, and do not stop processing if the operation fails
(because you can still use the results). Instead, display the value of the
cfftp.succeeded
and
No
if the operation failed.
Display a table with the results of the ListDir FTP command.
, you can reuse the connection to perform additional FTP operations until
cfftp
Last updated 8/5/2010
cfftp
tags by specifying the
call (the current directory of the
cfftp
variable, which is
Yes
if the connection is closed,
request.
cfftp
connection makes more sense,
cfftp
1242

Advertisement

Table of Contents
loading

Table of Contents