User Guide
cfftp: Connection: File and directory operations 177
Example
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>Move Image File to Remote Server:<br></p>
<!--- The image will be put into the root directory of the FTP server unless
otherwise noted.
i.e. remoteFile = "somewhere_put.jpg" vs remoteFile = "/support/
somewhere_put.jpg"
--->
<cfftp
connection = "myConnection"
action = "putFile"
name = "uploadFile"
transferMode = "binary"
localFile = "C:\files\upload\somewhere.jpg"
remoteFile = "somewhere_put.jpg"
>
<p>Did it succeed? <cfoutput>#cfftp.succeeded#</cfoutput>
<p>Close the connection:
<cfftp connection = "myConnection"
action = "close"
stopOnError = "Yes">
<p>Did it succeed? <cfoutput>#cfftp.succeeded#</cfoutput>