CFFTP: CONNECTION: FILE AND DIRECTORY OPERATIONS  
Description
Use this form of the cfftp tag to perform file and directory operations with cfftp.
 
Syntax
<cfftp
   action = "action"
   username = "name"
   password = "password"
   name = "query_name"
   server = "server"
   ASCIIExtensionList = "extensions"
   transferMode = "mode"
   failIfExists = "Yes" or "No"
   directory = "directory name"
   localFile = "filename"
   remoteFile = "filename"
   item = "directory or file"
   existing = "file or directory name"
   new = "file or directory name"
   proxyServer = "proxy server"
   passive = "Yes" or "No">
 
See also
cfhttp, cfldap, cfmail, cfpop
 
Usage
If 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:
  • getCurrentDir
  • getCurrentURL
  • existsDir
  • existsFile
  • exists
For more information, see Developing ColdFusion MX Applications.
Caution: Object (file and directory) names are case-sensitive.
 
Action (cfftp.ReturnValue variable)

The results of an action determine the value of the cfftp.returnValue variable.

cfftp action Value of cfftp.returnValue

getCurrentDir

String. Current directory.

getCurrentURL

String. Current URL.

existsDir

Yes or No.

existsFile

Yes or No.

exists

Yes or No.

 
Example

The following example opens a connection and gets 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 = "#DateFormat(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>
ACTION  
  Required if connection is not cached
 

FTP operation to perform.

  • changedir
  • createDir
  • listDir
  • removeDir
  • getFile
  • putFile
  • rename
  • remove
  • getCurrentDir
  • getCurrentURL
  • existsDir
  • existsFile
  • exists
USERNAME  
  Required if connection is not cached
 

User name to pass in the FTP operation.

PASSWORD  
  Required if action = "open"
 

Password to log in the user.

NAME  
  Required if action = "listDir"
 

Query name of directory listing.

SERVER  
  Required if FTP connection is not cached
 

FTP server to which to connect; for example, ftp.myserver.com.

ASCIIEXTENSIONLIST  
  Optional
 
Default value: "txt;htm;html;cfm;cfml;shtm;shtml;css;asp;asa"

Delimited list of file extensions that force ASCII transfer mode, if transferMode = "auto".

TRANSFERMODE  
  Optional
 
Default value: "Auto"
  • ASCII FTP transfer mode
  • Binary FTP transfer mode
  • Auto FTP transfer mode
FAILIFEXISTS  
  Optional
 
Default value: "Yes"
  • Yes: if a local file with same name exists, getFile fails
  • No
DIRECTORY  
  Required if action = "changedir", "createDir", "listDir", or "existsDir"
 

Directory on which to perform an operation.

LOCALFILE  
  Required if action = "getFile" or "putFile"
 

Name of the file on the local file system.

REMOTEFILE  
  Required if action = "getFile", "putFile", or "existsFile"
 

Name of the file on the FTP server file system.

ITEM  
  Required if action = "exists" or "remove"
 

Object of these actions: file or directory.

EXISTING  
  Required if action = "rename"
 

Current name of the file or directory on the remote server.

NEW  
  Required if action = "rename"
 

New name of file or directory on the remote server

PROXYSERVER  
  Optional
 

String. Name of the proxy server (s) to use, if proxy access is specified

PASSIVE  
  Optional
 
Default value: "No"
  • Yes: enable passive mode
  • No