// Get the object used to communicate with the server. FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftpserver" + "/" + label1.Text + "" + "Winter.jpg"); request.Method = WebRequestMethods.Ftp.UploadFile; //Path.GetFileName(filePath)); // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential("username", "password");
// Copy the contents of the file to the request stream. StreamReader sourceStream = new StreamReader(@"C:\\Winter.jpg");
I feel my problem is here somewhere? 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();
Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
response.Close();