Connection Caching  
 
 

Once you've established a connection with CFFTP, you can reuse the connection to perform additional FTP operations. To do this, you use the CONNECTION attribute when establishing a first connection to define and name an FTP connection object that stores information about the connection. Any additional FTP operations that use the same CONNECTION name automatically make use of the information stored in the connection object. This facility helps save the time necessary to connect and logon to an FTP server and improves file transfer operation performance.

When you access an already active FTP connection, you don't need to re-specify the following connection attributes:

  • USERNAME
  • PASSWORD
  • SERVER

In this case, developers have to make sure that when they use frames and multiple requests come in only one frame is going to use the connection object.

 
 
  Caching connections across multiple pages  
 
 

CFFTP caching is maintained only in the current page unless you explicitly assign a CFFTP connection to a variable with application or session scope. Assigning a CFFTP connection to an application variable could cause problems, since multiple users could access the same connection object at the same time. Creating a session variable for a CFFTP connection makes the most sense.

You cache a connection object for a session by assigning the connection name to a session variable:

 
 
  Example: Caching a connection  
 
<CFFTP ACTION=connect
    USERNAME="anonymous"
    PASSWORD="me@home.com"
    SERVER="ftp.eclipse.com"
    CONNECTION="Session.myconnection">

In this example, the connection cache remains available to other pages within the current session. Of course, you need to be sure that you've enabled session variables in your application first.

 
 
  Note  
 

Changes to a cached connection, such as changing RETRYCOUNT or TIMEOUT values, may require re-establishing the connection.

 
 
  Connection caching actions and attributes  
 
 

The following table shows which CFFTP attributes are required for CFFTP actions when employing connection caching. If connection caching is not used, the connection attributes USERNAME, PASSWORD, and SERVER must be specified.

CFFTP Required Attributes by Action 
Action
Attributes
Action
Attributes
Open
none
Rename
EXISTING
NEW
Close
none
Remove
SERVER
ITEM
ChangeDir
DIRECTORY
GetCurrentDir
none
CreateDir
DIRECTORY
GetCurrentURL
none
ListDir
NAME
DIRECTORY
ExistsDir
DIRECTORY
GetFile
LOCALFILE
REMOTEFILE
ExistsFile
REMOTEFILE
PutFile
LOCALFILE
REMOTEFILE
Exists
ITEM

 
 
  Example: An FTP session  
 

The following example opens an FTP connection, retrieves a file listing, showing file or directory name, path, URL, length, and modification date. Connection caching is used to maintain the link to the server, and automatic error checking is enabled.

<--- open FTP connection --->
<CFFTP CONNECTION=FTP
    USERNAME="betauser"
    PASSWORD="monroe"
    SERVER="beta.company.com"
    ACTION="Open"
    STOPONERROR="Yes">

<--- get current directory name --->
<CFFTP CONNECTION=FTP
    ACTION="GetCurrentDir"
    STOPONERROR="Yes">

<--- output directory name --->
<CFOUTPUT>
    FTP directory listing of #cfftp.returnvalue#.<p>
</CFOUTPUT>

<--- get directory info --->
<CFFTP CONNECTION=FTP
    ACTION="listdir"
    DIRECTORY="/*."
    NAME="q"
    STOPONERROR="Yes">

<--- output dirlist results --->
<HR>
<P>FTP Directory Listing:</P>

<CFTABLE QUERY="q" 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="Date(Format#lastmodified#)">
    <CFCOL HEADER="<B>IsDirectory</B>"
        TEXT="#isdirectory#">
</CFTABLE>


 
 
BackUp LevelNext
 
 

allaire     AllaireDoc@allaire.com
    Copyright © 1998, Allaire Corporation. All rights reserved.