如何将xml字符串上传到ftp?

时间:2013-02-26 12:42:29

标签: xml coldfusion ftp coldfusion-8

我正在使用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>

1 个答案:

答案 0 :(得分: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>

有点像这样。它应该足以让你开始。