title: How can I upload an image using FtpWebRequest?
body: <p>I have been working at building a feature for a client that will enable them to upload images from www.site1.com, storing the image URL to the database and storing the images to a file on www.site2.com/images. I have managed to upload a file to the target location, but when I try to open and view the image, it is said to contain errors. I've never really had to work with images, so I'm at a loss.</p>
  
  <p>This is the method used to upload the files:</p>
  
  <pre><code>public static void UpLoadImage(Stream image, string target)
      {
          FtpWebRequest req = (FtpWebRequest)WebRequest.Create("ftp://www.site2.com/images/" + target);
          req.UseBinary = true;
          req.Method = WebRequestMethods.Ftp.UploadFile;
          req.Credentials = new NetworkCredential("myUser", "myPass");
          StreamReader rdr = new StreamReader(image);
          byte[] fileData = Encoding.UTF8.GetBytes(rdr.ReadToEnd());
  
          rdr.Close();
          req.ContentLength = fileData.Length;
          Stream reqStream = req.GetRequestStream();
          reqStream.Write(fileData, 0, fileData.Length);
          reqStream.Close();
      }
  </code></pre>
  
  <p>This is where the method is called from (image1 is an HttpPostedFileBase):</p>
  
  <pre><code>myObject.UpLoadImage(image1.InputStream, storedTL.ID + "-1.png");
  </code></pre>
  
  <p>If there is a way that I can make this code work, or if there is an all around better way to do this, please help.</p>