Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 25, 2014 00:57
Show Gist options
  • Save bennadel/9753213 to your computer and use it in GitHub Desktop.
Save bennadel/9753213 to your computer and use it in GitHub Desktop.
My First ColdFusion 8 CFFTP Experience - Rocky But Triumphant
<!--- Get the file name of this test file. --->
<cfset strFilePath = ExpandPath( "./test.txt" ) />
<!---
Create a really large file. We need to do this because a
small file will be uploaded no matter what the timeout it
on the CFFTP.
--->
<cfsavecontent variable="strText">
<cfloop index="intI" from="1" to="100000" step="1"
>This is a really large file with a massive amount of text.
</cfloop>
</cfsavecontent>
<!--- Write the text to the test file. --->
<cffile
action="write"
file="#strFilePath#"
output="#strText#"
/>
<!--- Set up the FTP configuration. --->
<cfset objFTPProperties = {
Server = "****************",
Port = "***",
Username = "bnadel",
Password = "******",
Secure = true
} />
<!---
Now that the file has been written, we need to FTP it.
Let's create a connection object that will be used for
the following FTP commands.
When we name this connection, "objConnection", ColdFusion
caches the connection and allows us to execute future FTP
commands on this connection without passing in login
credentials or configuration.
--->
<cfftp
action="open"
connection="objConnection"
attributeCollection="#objFTPProperties#"
/>
<!--- "Put" the SQL file to cached connection. --->
<cfftp
action="putfile"
connection="objConnection"
localfile="#strFilePath#"
remotefile="/home/bnadel/#GetFileFromPath( strFilePath )#"
transfermode="auto"
/>
<!--- Close the connection. --->
<cfftp
action="close"
connection="objConnection"
/>
<!---
"Put" the SQL file to cached connection. This time, put
a 5 minute timeout on the PUT command. This should be more
than enough to handle the file size.
--->
<cfftp
action="putfile"
connection="objConnection"
localfile="#strFilePath#"
remotefile="/home/bnadel/#GetFileFromPath( strFilePath )#"
transfermode="auto"
timeout="300"
/>
<!---
Now that the file has been written, we need to FTP it.
Let's create a connection object that will be used for
the following FTP commands.
This time, let's move the TimeOut property to the OPEN
command. This will put the timeout property into our
cached connection object for use on all commands.
When we name this connection, "objConnection", ColdFusion
caches the connection and allows us to execute future FTP
commands on this connection without passing in login
credentials or configuration.
--->
<cfftp
action="open"
connection="objConnection3"
timeout="300"
attributeCollection="#objFTPProperties#"
/>
<!--- "Put" the SQL file to cached connection. --->
<cfftp
action="putfile"
connection="objConnection3"
localfile="#strFilePath#"
remotefile="/home/bnadel/#GetFileFromPath( strFilePath )#"
transfermode="auto"
/>
<!--- Close the connection. --->
<cfftp
action="close"
connection="objConnection3"
/>
<!---
Give the page some extra time to execute since we are going
to be executing some large FTP commands.
--->
<cfsetting requesttimeout="300" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment