shtea

shtea

  • NA
  • 1
  • 0

WebRequest error

Jul 30 2006 11:29 PM
Hi

I'm trying to upload a file into the server on my computer. I'm trying to test my code on my own computer. My code has something to do with FTP and I'm using FTPWebRequest.

This is my error: The remote server returned an error: (550) File unavailable (e.g., file not found, no access).

This is the part of the code that raises that error: Stream requestStream = request.GetRequestStream();

I cant figure out what's wrong with my code. I can find my file on the appropriate C:/filepath.xml if I look for it manually in my Computer. I already tried using %2f but it just wouldn't work. I can access the ftp in a browser with this address: ftp://stella.icatchit.com

Here's my code:
request = (FtpWebRequest)WebRequest.Create("ftp://stella.icatchit.com/%2fsamples/filepath.xml");
request.Method = WebRequestMethods.Ftp.UploadFile;

request.Credentials = new NetworkCredential("username", "password");
StreamReader sourceStream = new StreamReader(@"C:\filepath.xml");
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();

response = (FtpWebResponse)request.GetResponse();

Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

response.Close();
Console.ReadLine();