Uploading an xml direct to ftp
- by Joshua Maerten
i put this direct below a button:
XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement("Login");
XmlElement id = doc.CreateElement("id");
id.SetAttribute("userName", usernameTxb.Text);
id.SetAttribute("passWord", passwordTxb.Text);
XmlElement name = doc.CreateElement("Name");
name.InnerText = nameTxb.Text;
XmlElement age = doc.CreateElement("Age");
age.InnerText = ageTxb.Text;
XmlElement Country = doc.CreateElement("Country");
Country.InnerText = countryTxb.Text;
id.AppendChild(name);
id.AppendChild(age);
id.AppendChild(Country);
root.AppendChild(id);
doc.AppendChild(root);
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://users.skynet.be");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UsePassive = false;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("fa490002", "password");
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader();
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();
MessageBox.Show("Created SuccesFully!");
this.Close();
but i always get an error of the streamreader path, what do i need to place there ?
the meening is, creating an account and when i press the button, an xml file is saved to, ftp://users.skynet.be/testxml/
the filename is from usernameTxb.Text + ".xml".