0

我正在使用 ColdFusion 8、Windows 7 o/s 和 MySql 数据库。我通过从我的数据库中获取记录来创建一个 xml 文件。然后我想将它上传到我的 FTP 位置。我创建 xml 的代码如下。如何通过 FTP 上传此 xml?

<cfquery name="getData" datasource="datasourcename" dbtype="ODBC" username="myusername" password="mypassword">
    Select * from orders where orderid in (100,102,104)
</cfquery>

<cfset csvstr = createObject("java","java.lang.StringBuffer")>
<cfoutput query="getData">
    <cfset csvstr.append("?xml version=""1.0""?>") >
    <cfset csvstr.append("EDIData xmlns:eci=""http://www.abcdefg.com/CustomerReport"" ") >
    <cfset csvstr.append("       xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" ") >
    <cfset csvstr.append("       xsi:noNamespaceSchemaLocation=""CustomerReport.xsd"">") >
    <cfset csvstr.append("  MarketerDunsNumber>"& #MarketerDunsNumber# &"/MarketerDunsNumber>") >
    <cfset csvstr.append("  UtilityDunsNumber>"& #UtilityDunsNumber# &"/UtilityDunsNumber>") >
    <cfset csvstr.append("  Record RecordType="""& #RecordType# &""">") >
    <cfset csvstr.append("    NameCode>"& #NameCode# &"/NameCode>") >
    <cfset csvstr.append("    ContactName>"& #ContactName# &"/ContactName>") >
    <cfset csvstr.append("  /Record>") >
    <cfset csvstr.append("/EDIData>") >
    <cfset csvstr.append(Chr(13) & Chr(10)) >
    <cfset sFileName="CTData_"& #MarketerDunsNumber# &"_"& #UtilityDunsNumber# &".xml">
</cfoutput>
4

1 回答 1

2
<cfoutput   query=  "getData">

    <cfsavecontent  variable=   "sXMLContent">
    <EDIData    xmlns:eci="http://www.abcdefg.com/CustomerReport"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:noNamespaceSchemaLocation="CustomerReport.xsd">
        <MarketerDunsNumber>#MarketerDuinsNumber#</MarketerDunsNumber>
        <UtilityDunsNumber>#UtilityDunsNumber#</UtilityDunsNumber>
        <Record RecordType="#RecordType#">
            <NameCode>#NameCode#</NameCode>
            <ContactName>#ContactName#</ContactName>
        </Record>
    </EDIData>

    </cfsavecontent>

    <cfset  sTemporaryFileName= "xmlToFTP.xml" />
    <cfset  sRemoteFileName=    "xmlToFTP.xml" />

    <cffile action=     "write"
            file=       "#getTempDirectory()#/#sTemporaryFileName#"
            content=    "#toString( XMLParse( sXMLContent ) )#" />
    <cftry>
        <cfftp  action=     "putFile"
                server=     "some.ftp.server.com"
                user=       "user"
                password=   "password"
                localFile=  "#getTempDirectory()#/#sTemporaryFileName#"
                remoteFile= "#sRemoteFileName#" />

        <cfcatch>
            <!---   TODO: Do something with your error here.    --->

        </cfcatch>
    </cftry>

</cfoutput>

有点像这样的东西。这应该足以让你开始。

于 2013-02-26T13:24:10.843 回答