PDA

View Full Version : Example of how to use the ColdFusion CFFTP tag



Brian
June 12th, 2009, 06:37 PM
Here is an example of how to use the ColdFusion CFFTP tag to put a file from your local site, to an FTP site:


<cfftp action = "putFile"
server = "ftp.some_location.com"
username="UserName"
password="Password"
connection = "MyConn"
passive = "Yes"
localFile="D:\home\your_domain.com\wwwroot\localfile.txt"
remoteFile="remotefile.txt"
failifexists="no">

Did it succeed? <cfoutput>#cfftp.succeeded#</cfoutput>

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



Here is another example that creates the connection, lists the files, puts the file and then closes the connection:


<cfftp action = "open"
server = "ftp.some_location.com"
username="UserName"
password="Password"
connection = "MyConn"
passive = "Yes">

Did it open connection? <cfoutput>#cfftp.succeeded#</cfoutput><br />

<cfftp action = "LISTDIR"
stopOnError = "Yes"
name = "ListFiles"
directory = "/"
connection = "MyConn"
passive = "Yes">
<cfoutput query = "ListFiles">
#name#<br>
</cfoutput>


<cfftp connection = "MyConn"
action = "PutFile"
localFile="D:\home\your_domain.com\wwwroot\localfile.txt"
remoteFile="remotefile.txt"
failifexists="no"
passive = "Yes">

Did it put the file? <cfoutput>#cfftp.succeeded#</cfoutput><br />

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

Did it succeed in closing? <cfoutput>#cfftp.succeeded#</cfoutput>