I have an XML document. I don't want to save that XML in a physical path. How can I upload to ftp having xml document in memory.
So, i want to know whether it is possible to have an object in memory and save to ftp. I have the code for uploading to ftp which takes local path and remote path as parameters and upload it.
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:
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();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.