如何在coldfusion中通过FTP上传文件

时间:2013-02-26 09:21:59

标签: coldfusion

我使用下面的代码通过FTP上传文件。从第9行到第14行,显示“属性'连接'对标签无效的错误。(找到:[连接,本地文件,被动,动作,失败文件,远程文件])”请让我知道我去了哪里错误。提前致谢

1.<cftry>    
2.  <cfftp connection="Myftp"  
3.  action="open"  
4.  server="#ftpurl#"
5.  username="#form.ftpusername#"
6.  password="#form.ftppassword#">
7.  stoponerror="Yes">

8.  Did it open connection? <cfoutput>#cfftp.succeeded#</cfoutput><br />                            
9.  <cfftp connection = "Myftp"
10. action = "PutFile"
11. localFile="D:\home\\wwwroot\localfile.txt"
12. remoteFile="remotefile.txt"
13. failifexists="no"
14. passive = "Yes">

15. Did it put the file? <cfoutput>#cfftp.succeeded#</cfoutput><br />                       
16. <cfftp action="close" connection="Myftp">
17. <cfcatch>
18.     <cfset errText = "Please enter valid FTP details" />
19.     <cfset err = err + 1 />
20. </cfcatch>          
21.</cftry>

5 个答案:

答案 0 :(得分:1)

根据对问题的评论,这里的“错误”是CFEclipse字典文件中的一个错误,导致错误地将“连接”标记为无效属性。

提供的代码有效且正确执行。

答案 1 :(得分:0)

你在第6行有一个结束标记,看起来不合适。

6.  password="#form.ftppassword#">
7.  stoponerror="Yes">

应该是

6.  password="#form.ftppassword#"
7.  stoponerror="Yes">

答案 2 :(得分:-1)

使用<cffile>标记是在服务器而不是<cftfp>标记上传文件的最佳做法。 它简单而紧凑。设置语法..

<cffile 
action = "upload"
destination = "full pathname"
fileField = "form field"
accept = "MIME type|file type"
attributes = "file attribute or list"
mode = "permission"
nameConflict = "behavior"
result = "result name"> 

示例:

 <cfset destination = expandPath("www\img\QuesImages") />
 <cffile action="Upload" 
         fileField="QuesPhoto"   <!--name of input tag in form-->
         destination="#destination#" 
         nameConflict="Overwrite" 
         accept="image/jpeg, image/gif, image/png">

答案 3 :(得分:-2)

Correct parameters are 

 9.  <cfftp connection = "Myftp"
10. action = "PutFile"
11. localFile="D:\home\\wwwroot\localfile.txt"
12. remoteFile="remotefile.txt"
13. stoponerror="Yes"
14. passive = "Yes">`

答案 4 :(得分:-2)

您可以使用以下代码上传文件.........代码是单个文件的内容          

      

<cfcatch type="any">
    <cfoutput>#CFCATCH.message#</cfoutput>
    Unable to open FTP. Please check Server / Username / Password and then try again.1
    <cfabort>
</cfcatch>

    

<cfcatch type="Any">
    <cfoutput>C:#CFCATCH.message#</cfoutput>
    Unable to change directory. Please check server directory and then try again.2
    <cfabort>
</cfcatch>

         存在...替换......

        文件已存在,无法删除。请检查用户访问权限。
错误:D:#CFCATCH.message#3     

                 

    <cfcatch type="Any">
        <cfoutput>D:#CFCATCH.message#<br />
                    #CFCATCH.Detail#
        </cfoutput><br />
        There was a problem uploading your file. Please check User Access and then try again.4
        <cfabort>
    </cfcatch>
</cftry>

        上传文件时出现问题。请再试一次。错误:#CFCATCH.message#5