cfftp: Connection caching

Usage

After you establish a connection with cfftp, you can reuse it to perform additional FTP operations. To do this, you use the connection attribute 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 connection time and improves file transfer operation performance.

To keep the connection open throughout a session or longer, you can use a session or application variable as the connection name. However, if you do this, you must specify the full variable name with the close action when you are finished. Keeping a connection open prevents others from using the FTP server; therefore, you should close the connection as soon as possible.

Changes to a cached connection, such as changing retryCount or timeout values, might require reestablishing the connection.

Example

The following example opens a connection and retrieves a file listing showing 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 = "Date(Format#lastmodified#)">  
  <cfcol header = "<B>IsDirectory</B>" text = "#isdirectory#"> 
</cftable>

<P>Close the connection:
<cfftp connection = "myConnection"
    action = "close"
    stopOnError = "Yes">

<P>Did it succeed? <cfoutput>#cfftp.succeeded#</cfoutput>