[英]How do I upload XML document to FTP location
I have an XML document.我有一个 XML 文档。 I don't want to save that XML in a physical path.我不想将该 XML 保存在物理路径中。 How can I upload to ftp having xml document in memory.如何将内存中的 xml 文档上传到 ftp。
So, i want to know whether it is possible to have an object in memory and save to ftp.所以,我想知道是否有可能在内存中有一个对象并保存到 ftp。 I have the code for uploading to ftp which takes local path and remote path as parameters and upload it.我有上传到ftp的代码,它将本地路径和远程路径作为参数并上传。
UploadXMLToFTP(XmlDocument xml)
//Now this XMLDocument should be uploaded to ftp without saving in physical drive.
Following the MSDN Example of how to upload a file via FTP in .NET:遵循如何在 .NET 中通过 FTP 上传文件的MSDN 示例:
using System;
using System.IO;
using System.Net;
using System.Text;
...
public static void UploadXMLToFTP (XmlDocument xml)
{
// Get the object used to communicate with the server.
using(FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm"))
{
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");
// Copy the contents of the file to the request stream.
request.ContentLength = xml.OuterXml.Length;
Stream requestStream = request.GetRequestStream();
xml.Save(requestStream);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
response.Close();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.