Whatever message this page gives is out now! Go check it out!

ftp

Last update:
May 18, 2026
Note:
In ColdFusion (2018 release), script functions implemented as CFCs are deprecated in ColdFusion.

Description

Used to implement File Transfer Protocol (FTP) operations using CFScript.

Syntax

ModeSyntax
Creating the service
new ftp() or createObject("component","ftp")
Initializing the attributes
Any one of the following:
  • ftpService=new ftp(attribute-value pair)
  • ftpService.setAttributes(_attribute-value pair_)
  • ftpService.setA_ttributeName_(attribute_value)
  • ftpService.action_method(attribute-value_pair)
Executing the service action
ftpService.action_method(attribute-value_pair)

Properties

actionparam
buffersize
connection
passive
password
port
proxyserver
retrycount
server
stoponerror
timeout
username
fingerprint
key
passphrase
secure
ASCIIExtensionList
directory
existing
failifexists
item
localfile
name
new
remotefile
result
transfermode
allosize
All attributes supported by the tag cfftp can be used as attribute-value pairs. For example,
<cfftp userName="myUserName">
can be used as
ftpService.setUserName("myUserName");
For details, see the Attributes section for the cfftp tag.

See also

History

ColdFusion 9: Added this function.

Methods

The following FTP actions are available as methods. All methods have similar arguments and syntax.
  • open
    close
    quote
    site
    allo
    acct
    changeDir
    createDir
    listDir
    removeDir
    getFile
    putFile
    rename
    remove
    getCurrentDir
    getCurrentUrl
    existDir
    existsFile
    exists
  • Description
    All methods correspond to the FTP actions supported by the tag cfftp. For details of each method, refer to the relevant section for the tag cfftp.
    Returns
    All methods return a component with the following properties set:
  • prefix: Equivalent to the result attribute or cfftp scope
  • result: Applicable only for action="listdir"
    Syntax
    ftpService.methodName(attribute-value pair)
    Arguments
    All attributes supported by the tag cfftp.
  • setAttributes
    Description
    Sets attributes for the ftp function.
    Returns
    Nothing
    Syntax
    ftpService.setAttributes (attribute-value pair)
    Arguments
    All attributes supported by the tag cfftp.
  • getAttributes
    Description
    Gets the attributes that were set for the ftp function.
    Returns
    Returns a struct with all or some attribute values.
    Syntax
    ftpService.get_Attributes_ (attributelist)
    Arguments
    A comma-separated list of attributes. If no list is specified, all defined attributes are returned.
  • clear
    Description
    Removes all attributes added for the ftp function.
    Returns
    Nothing
    Syntax
    ftpService.clear()
    Arguments
    None

Usage

This function corresponds to the cfftp tag. For details, see the Usage section for the tag cfftp.

Example

<cfscript> /* Create a new ftp Service*/ ftpService = new ftp(); /* Set attributes using implicit setters */ ftpService.setUsername("myUsername"); ftpService.setPassword("myPassword"); ftpService.setServer("myFtpServer"); ftpService.setStopOnError("true"); ftpService.setConnection("conn"); /* Open connection to ftp server */ WriteOutput("<h4>Open a connection</h4>"); result = ftpService.open(); WriteOutput("<p>Did it succeed? " & result.getPrefix().succeeded & "<br></p>"); /* Get current directory */ WriteOutput("<h4>Get current directory</h4>"); result = ftpService.getcurrentdir(); WriteOutput("<p>Current Directory: " & "'" & result.getPrefix().returnvalue & "'" & "<br></p>"); /* List contents of the current directory */ WriteOutput("<h4>List directory contents</h4>"); result = ftpService.listdir(directory = "/",name="listDirs"); displayListing(result.getResult()); /* Move a file to the ftp server */ WriteOutput("<h4>Move File to Remote Server</h4>"); lFile = "C:\temp\artifacts.xml"; rFile = "artifacts.xml"; result = ftpService.putFile(transferMode="binary", localfile=lFile, remoteFile=rFile); WriteOutput("<p>Did it succeed? " & result.getPrefix().succeeded & "<br></p>"); /* Close connection to the ftp server */ WriteOutput("<h4>Close the connection</h4>"); ftpService.close(connection="conn"); WriteOutput("<p>Did it succeed? " & result.getPrefix().succeeded & "<br></p>"); </cfscript> <cffunction name="displayListing" hint="display ftp files"> <cfargument name="filesToList" required="true"> <cftable query = "filesToList" HTMLTable = "Yes" colHeaders = "Yes" border="1" maxrows="10"> <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> </cffunction>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page