View comments | RSS feed

cfftp: Opening and closing FTP server connections

Description

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

Syntax

<cfftp 
action = "action"
username = "name"
password = "password"
server = "server"
timeout = "timeout in seconds"
port = "port"
connection = "name"
proxyServer = "proxy server"
retryCount = "number"
stopOnError = "yes" or "no"
passive = "yes" or "no">

See also

cfhttp, cfldap, cfmail, cfpop

Attributes

Attribute Req/Opt Default Description

action

Required

 

FTP operation to perform.

  • open: creates an FTP connection
  • close: terminates an FTP connection

username

Required if action = "open"

 

User name to pass in the FTP operation.

password

Required if action = "open"

 

Password to log in the user.

server

Required if action = "open"

 

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

timeout

Optional

30

Value in seconds for the timeout of all operations, including individual data request operations.

port

Optional

21

Remote port to which to connect.

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.

proxyServer

Optional

 

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

retryCount

Optional

Number of retries until failure is reported.

stopOnError

Optional

no

  • yes: halts processing, displays an appropriate error.
  • 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)
      www.ietf.org/rfc/rfc0959.txt.
    • cfftp.errorText - Message text.

For conditional operations, use cfftp.errorCode. Do not use cfftp.errorText for this purpose.

passive

Optional

no

  • yes: enables passive mode.
  • no

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.

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>cfftp operations are usually of two types: <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>Open a connection <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: <cfftp action = "close" connection = "My_query" stopOnError = "Yes"> <p>Did it succeed? <cfoutput>#cfftp.succeeded#</cfoutput>

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting

Version 7

Comments


It has been said on Oct 5, 2005 at 12:01 PM :
The documentation needs to be more explicit about the "timeout" and the "stopOnError" attributes.
Specifically, what level of processing is halted on these?
The timeout seems to default to something much higher than the 30 seconds (listed in docs) when the action is "PUTFILE."
When the timeout is forced to a low number, and stopOnError is set to "No" , the <CFFTP> tag halts and throws a trappable error, but BOTH the calling cfm, AND the ftp "put" operation (running in the background) continue to process.

It leaves one wondering what the correct way is to use one CFM to initiate multiple file transfers running in parallel.
No screen name said on Jul 27, 2007 at 7:57 PM :
Is there a file size limit that CFFTP putfile can handle? I cannot FTP anything over 100 MB. Any thoughts ?
halL said on Jul 31, 2007 at 8:24 AM :
ColdFusion does not impose any limits, but your FTP server might have a limit.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00000260.htm