Connecting to an FTP server
<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">
Description
Use the connection
attribute of the cfftp
tag to establish a connection with an FTP server.
Category
Internet Protocol tags
See also
cfhttp,
cfldap,
cfmail,
cfpop
Attributes
Attribute |
Description |
action
|
Required. Determines the FTP operation to perform. To create an FTP connection, use open . To terminate an FTP connection, use close .
|
username
|
Required for action = "open" . User name to pass in the FTP operation.
|
password
|
Required for action = "open" . Password to log in the user.
|
server
|
Required for action = "open" . The FTP server to connect to, as in ftp.myserver.com
|
timeout
|
Optional. Value in seconds for the timeout of all operations, including individual data request operations. Defaults to 30 seconds
|
port
|
Optional. The remote port to connect to. Defaults to 21 for FTP.
|
connection
|
Optional. The name of the FTP connection. Used to cache a new FTP connection or to reuse an existing connection. If the username , password , and server attributes are specified, a connection is created, if no connection exists for the specified user. All calls to cfftp with the same connection name reuses the FTP connection information.
|
proxyServer
|
Optional. A string that contains the name of the proxy server (or servers) to use if proxy access is specified.
|
retryCount
|
Optional. Number of retries until failure is reported. Default is one (1).
|
stopOnError
|
Optional. Yes or No. When Yes, halts all processing and displays an appropriate error. Default is Yes. When No, three variables are populated:
cfftp.succeeded - Yes or No.
cfftp.errorCode - Error number. See the IETF Network Working Group RFC 959: File Transfer Protocol (FTP) for information about FTP error codes: http://www.ietf.org/rfc/rfc0959.txt.
cfftp.errorText - Message text that explains error type
Use cfftp.errorCode for conditional operations. Do not use cfftp.errorText for this purpose.
|
passive
|
Optional. Yes or No. Defaults to No. Indicates whether to enable passive mode.
|
Usage
If you use connection caching to an active FTP connection, you do not have to respecify the connection attributes:
Changes to a cached connection, such as changing retryCount
or timeout
values, might require reestablishing the connection.
Example
cfftp<!--- This example shows the use of cfftp --->
<html>
<head>g
<title>cfftp Example</title>
</head>
<body>
<H3>cfftp Example</H3>
<P>cfftp allows users to 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>
</body>
</html>