This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
464
|
Chapter 12: ColdFusion MX and FlashCom
We’ll use FTPServer instances to describe each FTP server to which to copy the
stream. The CFC that we’ll write next uses this data to perform the FTP transfers.
Using ColdFusion with FTP
You next want to create a CFC that will use FTP to copy a file from one server to one
or more other servers. The method should accept four parameters:
ftp_servers
An array of FTPServer objects
file
The name of the file to copy, such as an .flv stream
path
The path to the file on the local machine
transfermode
An optional parameter indicating the transfer mode (ASCII or binary); defaults
to binary, as should be used for .flv files
Create a new CFC document named FTPUtilities.cfc, and save it to a directory
named fcs_ftp in the web root. Add the following code to the file:
<cfcomponent>
<cffunction name="copyFile" access="remote">
<cfargument name="ftp_servers" type="array" />
<cfargument name="file" type="string" />
<cfargument name="path" type="string" />
<cfargument name="transfermode" type="string"
required="false" default="binary" />
//Loop through FTPServer objects, and use <cfftp> to copy the file.
<cfloop from="1" to="#ArrayLen(ftp_servers)#" index="i">
//Create the connection to the server.
<cfftp action="open" server="#ftp_servers[i].url#"
username="#ftp_servers[i].username#"
password="#ftp_servers[i].password#" connection="ftp_connection" />
//Copy the file.
<cfftp action="putfile" transfermode="#transfermode#"
localfile="#path##file#" remotefile="#ftp_servers[i].directory##file#"
passive="#ftp_servers[i].passive#" connection="ftp_connection" />
//Close the connection to the server.
<cfftp action="close" connection="ftp_connection" />
</cfloop>
</cffunction>
</cfcomponent>

Get Programming Flash Communication Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.