2013-02-26 80 views
2

我使用下面的代碼通過FTP上傳文件。從第9行到第14行,顯示錯誤:「屬性'連接'對標籤無效(發現:[connection,localfile,passive,action,failifexists,remotefile])」請讓我知道我去了哪裏錯誤。在此先感謝如何在coldfusion中通過FTP上傳文件

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> 
+0

我看不出什麼錯,立即與你發佈的代碼。你正在運行哪個版本的ColdFusion? – barnyr 2013-02-26 09:46:01

+0

我正在使用Coldfusion版本8 – RajVish 2013-02-26 09:50:19

+0

您使用的是CF8還是CF8.0.1?你試過把它拿出來嗎?只有在動作=「打開」或「關閉」時才需要。 – Travis 2013-02-26 10:45:25

回答

-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">` 
+1

什麼使這正確?你已經添加了屬性'stoponerror'(它已經默認爲yes),並刪除了'failifexists'(這是一個有效的屬性),沒有解釋原因。 – 2013-03-04 12:42:17

-1

使用<cffile>標籤上載文件的服務器,而不是<cftfp>標籤的最佳prectice。 它很容易和緊湊。看語法..

<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"> 
+1

儘管對於一般用途來說這是真的,但OP可能有他自己使用ftp的理由。 – 2013-02-26 18:35:16

+2

使用cffile不是最佳實踐 - 這是不同的做法。 cffile處理通過HTTP POST請求上傳的文件。 cfftp使用FTP協議發送/接收文件。 – 2013-03-04 12:36:25

-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

1

按照關於這個問題的意見,「錯誤」這裏是CFEclipse字典文件中的錯誤,導致「連接」的不正確的標籤作爲無效屬性。

提供的代碼有效且正確執行。

0

你在第6行看到不合適的結束標記。

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

應改爲

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

在這種情況下,您至少需要粘貼代碼** WITH **更正,然後突出顯示此事實。 – ishmaelMakitla 2016-06-21 20:00:21

+0

完成。我希望那樣更好。 – 2016-07-01 00:31:05