You are always writing the data in blocks of 1048576 bytes no matter how many are actually read.
Two choices:
1. Change the Write() to be:
ftpstream.Write(buffer, 0, bytesread);
2. Just have the two streams
deal with each other directly:
public bool UploadArticol(String adresaserver, String numefisier)
{
string uploadname = "articles\\"+numefisier+".dat";
try
{
FileInfo toupload = new FileInfo(uploadname);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://"+adresaserver+"/" + toupload.Name);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("lucian", "lucian");
Stream ftpstream = request.GetRequestStream();
using (FileStream file = File.OpenRead(uploadname))
{
file.CopyTo(ftpstream);
}
Console.WriteLine("Upload complete");
}
catch (Exception ee)
{
Console.WriteLine(ee.Message);
return false;
}
return true;
}