I’m using the msdn example here:
http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx
I changed the FileStream to a MemoryStream and it doesn’t read the bytes
when I change it back to FileStream it works fine.
Any clue?
Thanks
CompressMemoryStream();
Stream requestStream = _request.EndGetRequestStream(ar);
const int bufferLength = 2048;
byte[] buffer = new byte[bufferLength];
int count = 0;
int readBytes = 0;
do
{
//MemoryStream _compressedOutStream
//is created/filled by 'CompressMemoryStream()'
readBytes = _compressedOutStream.Read(buffer, 0, bufferLength);
requestStream.Write(buffer, 0, readBytes);
count += readBytes;
}
while (readBytes != 0);
requestStream.Close();
state.Request.BeginGetResponse(
new AsyncCallback(EndGetResponseCallback),
state
);
What’s the value of
readByteson the first iteration through the loop?My first guess would be that you made the same mistake that I often make: writing to a stream, then forgetting to rewind it to the beginning before starting to read back from it. If that’s the case, then
readByteswill be zero on the first (and only) loop iteration, because you’re at the end of the stream — there’s nothing to read.Try setting
stream.Position = 0before you start reading.