Skip to main content
Participating Frequently
April 23, 2010
Answered

Noob trying to upload a file to ftp

  • April 23, 2010
  • 1 reply
  • 427 views

Hi, everyone.

I am trying to create a form to upload a file to a server via ftp.  However I keep running into errors, especially concerning the destination of the file.  I have put the code below.

Any help would be appreciated.

Code:

<!--- Upload the file --->
<cfif isDefined("fileUpload")>
<cffile
action="upload"
filefield="fileUpload"
destination="">
</cfif>
<form enctype="multipart/form-data" method="post">
<input type="file" name="fileUpload" /><br />
<input type="submit" value="Upload File" />
</form>

<!--- Get the filename
<cfset FileName = CFFILE.ServerFile> --->

<!--- BEGIN REMOVE - DEBUGGING
<cfoutput>#FileName#</cfoutput>
END REMOVE - DEBUGGING --->

<!--- Open an FTP Connection --->
<cfftp
connection = "myConnection"
username = ""
password = ""
server = "129.1.26.15"
action = "open"
stopOnError = "Yes">

<!--- BEGIN REMOVE - DEBUGGING --->
<p>Did Open Connection succeed? <cfoutput>#cfftp.succeeded#</cfoutput>
<!--- END REMOVE - DEBUGGING --->

<!--- put the file --->
<cfftp
connection = "myConnection"
action = "putFile"
transferMode = "binary"
localFile = "F:\temp\#FileName#"
remoteFile = "129.1.26.15/users/mis405spr10/rsuciu/omfoto/upload/NEW_#FileName#">

<!--- BEGIN REMOVE - DEBUGGING --->
<p>Did Upload succeed? <cfoutput>#cfftp.succeeded#</cfoutput>
<!--- END REMOVE - DEBUGGING --->

<!--- Close the connection --->
<cfftp
connection = "myConnection"
action = "close"
stopOnError = "Yes">

<!--- BEGIN REMOVE - DEBUGGING --->
<p>Did Close Connection succeed? <cfoutput>#cfftp.succeeded#</cfoutput>
<!--- END REMOVE - DEBUGGING --->

<!--- Delete the local file --->
<cffile
action="delete"
file="C:\Inetpub\wwwroot\TEMP\#FileName#">

This topic has been closed for replies.
Correct answer Dan_Bracuk

Instead of cfftp, use cffile.  Details are in the cfml reference manual.

If you don't have a manual googling the name of the tag gets you to the right page pretty quickly.

1 reply

Dan_BracukCorrect answer
Inspiring
April 23, 2010

Instead of cfftp, use cffile.  Details are in the cfml reference manual.

If you don't have a manual googling the name of the tag gets you to the right page pretty quickly.