For the complete experience, please enable JavaScript in your browser. Thank you!

  • Creative Cloud
  • Photoshop
  • Illustrator
  • InDesign
  • Premiere Pro
  • After Effects
  • Lightroom
  • See all
  • See plans for: businesses photographers students
  • Document Cloud
  • Acrobat DC
  • eSign
  • Stock
  • Elements
  • Marketing Cloud
  • Analytics
  • Audience Manager
  • Campaign
  • Experience Manager
  • Media Optimizer
  • Target
  • See all
  • Acrobat Reader DC
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player
  • All products
  • Creative Cloud
  • Individuals
  • Photographers
  • Students and Teachers
  • Business
  • Schools and Universities
  • Marketing Cloud
  • Document Cloud
  • Stock
  • Elements
  • All products
  • Get Support
    Find answers quickly. Contact us if you need to.
    Start now >
  • Learn the apps
    Get started or learn new ways to work.
    Learn now >
  • Ask the community
    Post questions and get answers from experts.
    Start now >
    • About Us
    • Careers At Adobe
    • Investor Relations
    • Privacy  |  Security
    • Corporate Responsibility
    • Customer Showcase
    • Events
    • Contact Us
News
    • 3/22/2016
      Adobe Summit 2016: Are You An Experience Business?
    • 3/22/2016
      Adobe Announces Cross-Device Co-op to Enable People-Based Marketing
    • 3/22/2016
      Adobe and comScore Advance Digital TV and Ad Measurement
    • 3/22/2016
      Adobe Marketing Cloud Redefines TV Experience
Interacting with Remote Servers / 

Performing file operations with cfftp

Adobe Community Help


Applies to

  • ColdFusion

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

The cfftp tag lets you perform tasks on remote servers using File Transfer Protocol (FTP). You can use cfftp to cache connections for batch file transfers when uploading or downloading files.

Note: To use cfftp, select the Enable ColdFusion Security option on the Sandbox Security page in the Security area in the ColdFusion Administrator. (In the Standard Edition, select Security > Basic Security.)

For server/browser operations, use the cffile, cfcontent, and cfdirectory tags.
Using cfftp involves two major types of operations: connecting, and transferring files. The FTP protocol also provides commands for listing directories and performing other operations. For a complete list of attributes that support FTP operations and additional details on using the cfftp tag, see the CFML Reference.

Open an FTP connection and retrieve a file listing

  1. Create a ColdFusion page with the following content:

    <html>
    <head>
    <title>FTP Test</title>
    </head>

    <body>
    <h1>FTP Test</h1>
    <!--- Open ftp connection --->
    <cfftp connection="Myftp"
    server="MyServer"
    username="MyUserName"
    password="MyPassword"
    action="Open"
    stoponerror="Yes">

    <!--- Get the current directory name. --->
    <cfftp connection=Myftp
    action="GetCurrentDir"
    stoponerror="Yes">

    <!--- output directory name --->
    <cfoutput>
    The current directory is:#cfftp.returnvalue#<p>
    </cfoutput>

    <!--- Get a listing of the directory. --->
    <cfftp connection=Myftp
    action="listdir"
    directory="#cfftp.returnvalue#"
    name="dirlist"
    stoponerror="Yes">
    <!--- Close the connection.--->
    <cfftp action="close" connection="Myftp">
    <p>Did the connection close successfully?
    <cfoutput>#cfftp.succeeded#</cfoutput></p>

    <!--- output dirlist results --->
    <hr>
    <p>FTP Directory Listing:</p>

    <cftable query="dirlist" colheaders="yes" htmltable>
    <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>

  2. Change MyServer to the name of a server for which you have FTP permission.
  3. Change MyUserName and MyPassword to a valid user name and password.To establish an anonymous connection, enter "anonymous" as the user name and an e-mail address (by convention) for the password.
  4. Save the file as ftp_connect.cfm in the myapps directory under your web_root and view it in the web browser.
Reviewing the code

The following table describes the code and its function:

Code

Description

 

<cfftp connection="Myftp" server="MyServer"
username="MyUserName" password="MyPassword"
action="Open" stoponerror="Yes">

 

Open an FTP connection to the MyServer server and log on as MyUserName. If an error occurs, stop processing and display an error. You can use this connection in other cfftp tags by specifying the Myftp connection.

 

<cfftp connection=Myftp action="GetCurrentDir" stoponerror="Yes">
<cfoutput>
The current directory is: #cfftp.returnvalue#<p>
</cfoutput>

 

Use the Myftp connection to get the name of the current directory; stop processing if an error occurs. Display the current directory.

 

<cfftp connection=Myftp action="ListDir"
directory="#cfftp.returnvalue#" name="dirlist" stoponerror="Yes">

 

Use the Myftp connection to get a directory listing. Use the value returned by the last cfftp call (the current directory of the connection) to specify the directory to list. Save the results in a variable named dirlist (a query object). Stop processing if an error occurs.

 

<cfftp action="close" connection="Myftp">
<p>Did the connection close successfully?
<cfoutput>#cfftp.succeeded#</cfoutput></p>

 

Close the connection, and do not stop processing if the operation fails (because you can still use the results). Instead, display the value of the cfftp.succeeded variable, which is Yes if the connection is closed, and No if the operation failed.

 

<cftable query="dirlist" colheaders="yes" htmltable>
<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>

 

Display a table with the results of the ListDir FTP command.

After you establish a connection with cfftp, you can reuse the connection to perform additional FTP operations until either you or the server closes the connection. When you access an already-active FTP connection, you need not respecify the user name, password, or server. In this case, make sure that when you use frames, only one frame uses the connection object.

Note: For a single simple FTP operation, such as GetFile or PutFile, you need not establish a connection. Specify all the necessary login information, including the server and any login and password, in the single cfftp request.

Caching connections across multiple pages

The FTP connection established by the cfftp tag is maintained only in the current page unless you explicitly assign the connection to a variable with Application or Session scope.
Assigning a cfftp connection to an application variable could cause problems, since multiple users could access the same connection object at the same time. Creating a session variable for a cfftp connection makes more sense, because the connection is available to only one client and does not last past the end of the session.

Example: caching a connection

<cflock scope="Session" timeout=10>
<cfftp action="Open"
username="anonymous"
password="me@home.com"
server="ftp.eclipse.com"
connection="Session.myconnection">
</cflock>

In this example, the connection cache remains available to other pages within the current session. For this approach to work, enable session variables in your application, and lock code that uses session variables. For more information on locking, see Using Persistent Data and Locking.

Note: Changing connection characteristics, such the retrycount or timeout values, could require you to re-establish the connection.

Connection actions and attributes

The following table shows the available cfftp actions and the attributes they require when you use a named (that is, cached) connection. If you do not specify an existing connection name, specify the username, password, and server attributes.

Action

Attributes

Action

Attributes

Open

none

Rename

existingnew

Close

none

Remove

serveritem

ChangeDir

directory

GetCurrentDir

none

CreateDir

directory

GetCurrentURL

none

ListDir

namedirectory

ExistsDir

directory

RemoveDir

directory

ExistsFile

remotefile

GetFile

localfileremotefile

Exists

item

PutFile

localfileremotefile

 

 

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

Choose your region United States (Change)   Products   Downloads   Learn & Support   Company
Choose your region Close

Americas

Europe, Middle East and Africa

Asia Pacific

  • Brasil
  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Cyprus - English
  • Česká republika
  • Danmark
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Greece - English
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • Malta - English
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • Southeast Asia (Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam) - English
  • 台灣

Commonwealth of Independent States

  • Includes Armenia, Azerbaijan, Belarus, Georgia, Moldova, Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Ukraine, Uzbekistan

Copyright © 2016 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

AdChoices