View comments | RSS feed
Contents > CFML Reference > ColdFusion Tags > cfftp: Connection: File and directory operations PreviousNext

cfftp: Connection: File and directory operations

Use this form of the cfftp tag to perform file and directory operations with cfftp.

<cfftp 
action = "action"
username = "name"
password = "password"
name = "query_name"
server = "server"
ASCIIExtensionList = "extensions"
transferMode = "mode"
failIfExists = "Yes" or "No"
directory = "directory name"
localFile = "filename"
remoteFile = "filename"
item = "directory or file"
existing = "file or directory name"
new = "file or directory name"
proxyServer = "proxy server"
passive = "Yes" or "No">

cfhttp, cfldap, cfmail, cfpop

Attribute

Req/Opt

Default

Description

action

Required if connection is not cached

 

FTP operation to perform.

  • changedir
  • createDir
  • listDir
  • removeDir
  • getFile
  • putFile
  • rename
  • remove
  • getCurrentDir
  • getCurrentURL
  • existsDir
  • existsFile
  • exists

username

Required if connection is not cached

 

User name to pass in the FTP operation.

password

Required if action = "open"

 

Password to log in the user.

name

Required if action = "listDir"

 

Query name of directory listing.

server

Required if FTP connection is not cached

 

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

ASCIIExtensionList

Optional

txt;htm;html;cfm;cfml;
shtm;shtml;
css;asp;asa

Delimited list of file extensions that force ASCII transfer mode, if transferMode = "auto".

transferMode

Optional

Auto

  • ASCII FTP transfer mode
  • Binary FTP transfer mode
  • Auto FTP transfer mode

failIfExists

Optional

Yes

  • Yes: if a local file with same name exists, getFile fails
  • No

directory

Required if action = "changedir", "createDir", "listDir", or "existsDir"

 

Directory on which to perform an operation.

localFile

Required if action = "getFile" or "putFile"

 

Name of the file on the local file system.

remoteFile

Required if action = "getFile", "putFile", or "existsFile"

 

Name of the file on the FTP server file system.

item

Required if action = "exists" or "remove"

 

Object of these actions: file or directory.

existing

Required if action = "rename"

 

Current name of the file or directory on the remote server.

new

Required if action = "rename"

 

New name of file or directory on the remote server

proxyServer

Optional

 

String. Name of the proxy server (s) to use, if proxy access is specified

passive

Optional

No

  • Yes: enable passive mode
  • No

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.

If action = "listDir", the attributes column returns directory or normal. Other platform-specific values, such as hidden and system, are no longer supported.

If action = "listDir", a mode column is returned. The column contains an octal string representation of UNIX permissions; for example, "777."

The cfftp.returnValue variable provides the return value for these actions:

For more information, see Developing ColdFusion MX Applications.

Caution: Object (file and directory) names are case-sensitive.

Action (cfftp.ReturnValue variable)

The results of an action determine the value of the cfftp.returnValue variable.

cfftp action

Value of cfftp.returnValue

getCurrentDir

String. Current directory.

getCurrentURL

String. Current URL.

existsDir

Yes or No.

existsFile

Yes or No.

exists

Yes or No.

The following example opens a connection and gets a file listing showing file or directory name, path, URL, length, and modification date.

<p>Open a connection
<cfftp connection = "myConnection" 
   username = "myUserName"
   password = "myUserName@allaire.com"
   server = "ftp.allaire.com"
   action = "open" 
   stopOnError = "Yes"> 

<p>Did it succeed? <cfoutput>#cfftp.succeeded#</cfoutput>
<cfftp connection = "myConnection"
    action = "LISTDIR"
    stopOnError = "Yes"
    name = "ListDirs"
    directory = "/">

<p>FTP Directory Listing:<br> 
<cftable query = "ListDirs" HTMLTable = "Yes" colHeaders = "Yes"> 
   <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>

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

Contents > CFML Reference > ColdFusion Tags > cfftp: Connection: File and directory operations PreviousNext

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

Version 6.1

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

Comments


lbryngel said on Feb 19, 2004 at 8:36 AM :
Suggestion: Clarify what text needs to be put in for Transfermode Attribute.

ASCII: ASCII FTP transfer mode
Binary: Binary FTP transfer mode
Auto: Auto FTP transfer mode

We are working to improve the examples in the ColdFusion reference pages. We propose to replace the current example on this page with the the following example. If you have any comments on this example, add them to this page.

Addition for current sample to be inserted between the FTP Listing Directory section and the Closing Connection Section:

<p>Move Image File to Remote Server:<br></p>
<!--- The image will be put into the root directory of the FTP server unless
other wise noted
i.e. remoteFile = "somewhere_put.jpg" vs remoteFile = "/support/somewhere_put.jpg"
--->
<cfftp
connection = "myConnection"
action = "putFile"
name = "uploadFile"
transferMode = "binary"
localFile = "C:\filesPload\somewhere.jpg"
remoteFile = "somewhere_put.jpg"
>
<p>Did it succeed? <cfoutput>#cfftp.succeeded#</cfoutput>
MarkZet said on Jun 11, 2004 at 4:14 AM :
There seems to be an undocumented attribute "port" to specify an alternative port number to connect to.
Michael said on Nov 16, 2004 at 10:32 AM :
In your proposed example, you have name = "uploadFile", but for a transfer, is name a required attribute? If not, I would ask that you remove it.
Mindframe said on Jan 6, 2005 at 2:31 PM :
The documentation for cfftp should be updated to specify what is required for the action = "remove"
ShaniDagr8 said on Feb 4, 2005 at 12:04 PM :
How do I create a new file on server cffile does not have any such attribute to create a file!! Please email me any suggestions to s4shani83@hotmail.com. this is really urgent!!
TomGru said on Apr 4, 2005 at 4:46 AM :
If you are having CFFTP connection problems because of the proxy server (as i had) try to user the proxyserver in the servervariable:

<cfftp action = "open"
username = "user@80.119.134.111"
password = "pw0846"
server = "proxyserver.ptx.com"
name = "test" >
julyo said on Apr 21, 2005 at 4:40 AM :
Hello, this code return an error: " The request has exceeded the allowable time limit Tag: cfftp".

How can I to solve the problem?


<cffunction name="subirArchivo"
returntype="numeric">
<cfargument name="servidor" required="yes">
<cfargument name="user" required="yes">
<cfargument name="pass" required="yes">
<cfargument name="directorio" required="yes">
<cfargument name="localFile" required="yes">
<cfargument name="remoteFile" required="yes">

<cfftp action = "open"
username = "#user#"
connection = "images"
password = "#pass#"
server = "#servidor#"
passive="yes"
stopOnError = "Yes"
timeout = "1200"
retrycount="10">

<cfloop index="i" from="1" to="#ListLen(directorio, '/')#">
<cfset tempDir = #GetToken(directorio, i, '/')#>
<cfftp action = "existsDir"
stopOnError = "Yes"
directory = "#tempDir#"
passive="yes"
connection = "images"
timeout = "600"
retrycount="10">
<!-- Si no existe lo creamos -->
<cfif cfftp.ReturnValue EQ 'No'>
<cfftp action = "CreateDir"
stopOnError = "Yes"
directory = "#tempDir#"
passive="yes"
connection = "images"
timeout = "500"
retrycount="10">
<cfftp action = "CHANGEDIR"
stopOnError = "Yes"
directory = "#tempDir#"
passive="yes"
connection = "images"
timeout = "600"
retrycount="10">
<cfelse>
<!-- Existe -->
<cfftp action = "CHANGEDIR"
stopOnError = "Yes"
directory = "#tempDir#"
passive="yes"
connection = "images"
timeout = "600"
retrycount="10">
</cfif>
</cfloop>

<cfftp action = "putFile"
stopOnError = "Yes"
localFile = "#localFile#"
remoteFile = "#remoteFile#"
passive="yes"
connection = "images">

<cfftp action = "close"
connection = "images">

<cfreturn 1>
</cffunction>

Thanks
No screen name said on Nov 13, 2005 at 12:48 AM :
Well, it's probably a bit late to be responding to the guy who posted this,
having found it about seven months too late, but since it would've saved
me a few minutes to have found it here, I thought I'd post the solution. If
you're using cfftp to handle fairly large files (at least anything that takes
more than 30 seconds to upload) you've probably encountered this
timeout error. One bad way to get around it is to just tell the close
connection statement to ignore errors. The good way to do it is with this
tag:

<cfsetting requestTimeOut = "120">

120 being 2 minutes, or 120 seconds. Of course, you probably want to
make it a little higher in this case. This temporarily changes the server
timeout, which is suggested to be at 30 seconds, so operations generally
requiring more time will be allowed to have it. The reason it's supposed
to be at 30 seconds is because the server will get bogged down if every
page is allowed to run on and on forever. It's supposed to be used only
when you know you'll need more time.

 

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

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p41.htm