i'm trying to upload a file to localhost using FTP with below code. i get error: "Unable to connect to the remote server" on
Stream requestStream = request.GetRequestStream();What i'm doing wrong? i'm using xamp as the local server.
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://localhost/");
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("root", "");
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader("test.txt");
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();
Thanks.
This post has been edited by KasunL: 01 October 2012 - 12:54 AM

New Topic/Question
Reply



MultiQuote




|