View comments | RSS feed

cfftp: Connecting to an FTP server

Description

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

Syntax

<cfftp 
  action = "action"
  username = "name"
  password = "password"
  server = "server"
  timeout = "timeout in seconds"
  port = "port"
  connection = "name"
  proxyServer = "proxyserver"
  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: create an FTP connection
  • close: terminate an FTP connection
For more information, see "cfftp: Connection caching".
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

Name of the FTP connection. Used to cache a new FTP connection or to reuse a 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 information.
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.
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: enable passive mode
  • No

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.

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 | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


rbils@amkor.com said on May 30, 2002 at 3:55 PM :
Argh! For some reason, the AGENTNAME attribute is now gone from the CFFTP tag (in MX). This isn't in the release notes, nor is it in the docs anywhere. This is a big bummer as I have a bunch of CFFTP code that now has to be changed to work with MX. Any chance of getting this attribute back? It's really useful for filtering out FTP requests in log files.
ctina said on Jul 16, 2002 at 6:08 PM :
Update from Macromedia, responding to rbils@amkor.com, re the CFFTP tag AGENTNAME attribute:

Rob, we've entered an enhancement request to reinstate the agentname attribute. CF 5 ignored this attribute; using it was valid, in that it did not cause an error, but CF did not use the value.

No screen name said on Dec 9, 2003 at 8:21 PM :
Can anyone tell me what does CFFTP ErrorCode 3 means? I'm searching the whole site and I can't find any. Thanks.

 

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

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/Tags-pt141.htm