I have a remote folder with n files and I need to copy content in another remote file. I guess it can be done through streams, and this is what I tried:
WebRequest destRequest = WebRequest.Create(destFile);
destRequest.Method = "PUT";
destRequest.Headers.Add("x-ms-blob-type", "BlockBlob"); //just an example with Azure blob, doesn't matter
using (Stream destStream = destRequest.GetRequestStream())
{
string sourceName = "mysourcefolder";
int blockSize = 8388608; //all the files have the same lenght, except one (sometimes)
for (int i = 0; i < n; i++)
{
string source = sourceName + i;
WebRequest sourceRequest = WebRequest.Create(source);
destRequest.Method = "GET";
HttpWebResponse destResp = (HttpWebResponse)destRequest.GetResponse();
using (Stream sourceStream = destResp.GetResponseStream())
{
sourceStream.CopyTo(destStream, blockSize);
}
}
Console.Write("ok");
}
}
catch (Exception e)
{
Console.Write("nope !");
}
There are multiple issues in my code:
1) I have to specify the lenght in my PUT request. Probably it is blockSize*n
since I have no exceptions about this;
2) If that is the case, I have still the exception Cannot close stream until all bytes are written
. What does it means?