I am uploading a file through FTP that is 613.6 kb, it is a PDF file. When it arrives on the server it is now 82 KB.
in my Web.Config I have
<httpRuntime executionTimeout="7200" maxRequestLength="2097151" requestValidationMode="2.0"/>
my Code is this
void UploadFileToFtp(FileInfo file, FtpWebRequest req)
{
int buffLength = 2048;
using (var reader = new BinaryReader(file.OpenRead(), Encoding.Default))
{
using (var writer = new BinaryWriter(req.GetRequestStream()))
{
while (reader.PeekChar() > 0) writer.Write(reader.ReadBytes(buffLength));
writer.Flush();
writer.Close();
}
reader.Close();
}
}
I thought it had something to do with the Encoding so I tried ASCII, Default and Unicode none of which made a diffrence. I added the Flush and the Close thinking that was doing it, but no help either. I was getting an error regarding the encoding and once I added that the error went away, but I have no other errors.
Could it be that the file contains zeros and your comparison should be
reader.PeekChar() >=0rather thanreader.PeekChar() > 0?