I used this code to upload image to ftp. but image is corrupted.
image im trying to upload is a Base64
string.i converted to stream and passed it to UpLoadImage.
public static void UpLoadImage(Stream image, string target)
{
FtpWebRequest req = (FtpWebRequest)WebRequest.Create("ftp://www.examp.com/images/" + target);
req.UseBinary = true;
req.Method = WebRequestMethods.Ftp.UploadFile;
req.Credentials = new NetworkCredential("UserNm", "PassWd");
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();
}
Instead of:
StreamReader rdr = new StreamReader(image); byte[] fileData = Encoding.UTF8.GetBytes(rdr.ReadToEnd()); rdr.Close();
if i use byte[] fileData = File.ReadAllBytes(image);
it gives me a error, filename is to more the 260 character.
Please can someone help to solve this..