I have the following code to upload a pdf file through ftp :
try
{
if (!File.Exists(localPath))
throw new FileNotFoundException(localPath);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(ftpPath));
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Proxy = null;
request.UseBinary = true;
request.Credentials = new NetworkCredential(username, password);
byte[] data = File.ReadAllBytes(localPath);
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
if (response == null || (response.StatusCode != FtpStatusCode.CommandOK))
throw new Exception("Upload failed.");
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
throw e;
}
My problem that it uploads only text without images . How could i upload a file without reading it? I mean i just want to select and rename the file and upload it.