Description

To establish a connection with an FTP server, use the open action with a connection attribute.

Syntax

<cfftp 
action = "open|close|quote|site|allo|acct"
actionparam = "command or account information" 
buffersize = "number" 
connection = "name" 
passive = "yes|no" 
password = "password" 
port = "port" 
proxyServer = "proxy server" 
retryCount = "number" 
server = "server" 
stopOnError = "yes|no"
systemtype = "windows | unix"
timeout = "time-sout in seconds" 
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.

See also

cfhttpcfldapcfmailcfpop

Attributes

Attribute

Req/Opt

Default

Description

action

Required

 

FTP operation to perform.

  • open: creates an FTP connection.
  • close: terminates an FTP connection.
  • quote: sends a command verbatim to the FTP server.
  • site: executes a site-specific command.
  • allo: allocates memory for operations, such as putting large files, on the server.
  • acct: sends account information on systems that require it.

actionparam

Optional

 

Used only when action is quote, site, or acct. Specifies the command when action is quote or site; specifies account information when action is acct.

buffersize

Optional

 

Buffer size in bytes.

connection

Optional, but always used with open or close

 

Name of the FTP connection. If you specify the username, password, and server attributes, and if no connection exists for them, ColdFusion creates one. Calls to cfftp with the same connection name reuse the connection.

passive

Optional

no

  • yes: enables passive mode.
  • no

password

Required if action = "open"

 

Password to log in the user.

port

Optional

21

Remote port to which to connect.

proxyServer

Optional

 

String. Name of proxy server (or servers) to use, if proxy access is specified.

retryCount

Optional

1

Number of retries until failure is reported.

server

Required if action = "open"

 

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

stopOnError

Optional

yes

  • yes: halts processing, displays an appropriate error.
  • no: if secure="no", populates these variables:
  • cfftp.succeeded: yes or no.
  • cfftp.errorCode: error number. See the IETF Network Working Group RFC 959: File Transfer Protocol (FTP) at www.ietf.org/rfc/rfc0959.txt.
  • cfftp.errorText: Message text.
    For conditional operations, use cfftp.errorCode. Do not use cfftp.errorText for this purpose.

systemType

Optional

 

Possible values for the attribute are:

  • Windows: If specified, CFFTP treats the response as Windows-style directory listing.
  • Unix: If specified, CFFTP treats the response as Unix-Style directory listing.

timeout

Optional

30

Value in seconds for the time-out of all operations, including individual data request operations.

username

Required if action = "open"

 

User name to pass in the FTP operation.

Usage

When you establish a connection with cfftp action="open" and specify a name in the connection attribute, ColdFusion caches the connection so that you can reuse it to perform additional FTP operations. When you use a cached connection for subsequent FTP operations, you do not have to specify the username, password, or server connection attributes. The FTP operations that use the same connection name automatically use the information stored in the cached connection. Using a cached connection helps save connection time and improves file transfer performance. You do not need to open a connection for single, simple, FTP operations, such as GetFile or PutFile.
With any action except close, you can set the internal buffer size by specifying buffersize. If you specify quote, site, allo, or acct as the action and set secure="yes" an error is generated. You specify the command to send to the FTP server in the actionparam attribute when you specify site or quote as the action. When site is the action, you use the actionparam attribute to specify the site-specific information.
To keep a connection open throughout a session or longer, put the connection name in the Session or Application scope; for example, specify connection="Session.FTPConnection". However, if you do this, you must specify the full variable name in all FTP operations, and you must use the close action when you are finished. Keeping a connection open prevents others from using the FTP server; so close a connection as soon as possible. If you do not assign the connection name to Session or Application variable, the connection remains open for the current page only, and you do not have to close it manually. Changes to a cached connection, such as changing retryCount or timeout values, might require reestablishing the connection.

Example

<p>cfftp lets users implement File Transfer Protocol operations. By default, cfftp caches 
an open connection to an FTP server.</p> 
<p>cfftp operations are usually of two types:</p> 
<ul> 
<li>Establishing a connection 
<li>Performing file and directory operations 
</ul> 
<p>This example opens and verifies a connection, lists the files in a directory, and closes 
the connection.</p> 
<p>Open a connection</p> 
<cfftp action = "open" 
username = "anonymous" 
connection = "My_query" 
password = "youremail@email.com" 
server = "ftp.tucows.com" 
stopOnError = "Yes"> 
<p>Did it succeed? <cfoutput>#cfftp.succeeded#</cfoutput> 
<p>List the files in a directory: 
<cfftp action = "LISTDIR" 
stopOnError = "Yes" 
name = "ListFiles" 
directory = "/" 
connection = "my_query"> 
<cfoutput query = "ListFiles"> 
#name#<br> 
</cfoutput> 

<p>Close the connection:</p> 
<cfftp action = "close" 
connection = "My_query" 
stopOnError = "Yes"> 
<p>Did it succeed? <cfoutput>#cfftp.succeeded#</cfoutput>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy