0

I need to get a file from my server via FTP into a memory stream and then decompress it so I can further work with it.

I do the below but the decompressed file is truncated every time.

I can see that the FTP part is working correctly (I checked that ms.Length equals the correct file size on the server (about 700KB)).

res.Length is only about 400K but it should be about 10MB. (also I can see in the Console.WriteLine(res) that the file is truncated).

I get a MemoryStream from my FTP code then...

var decompress = new GZipStream(ms, CompressionMode.Decompress);
using (var sr = new StreamReader(decompress))
{
  var res = sr.ReadToEnd();
  Console.WriteLine(res);
}
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Matt M.
  • 812
  • 3
  • 16
  • 24
  • 1
    Either the server already sends some corrupted data, the data gets corrupted in transit, or the compressed data uses a compression flavor not fully supported by GZipStream. Suggestion: Download the file manually (with an FTP) client and try to decompress it with some reliable/known compression utility. If file is okay, try downloading the file through your program, but instead of using a MemoryStream, write the downloaded data to a file. Again, try to decompress this file then with a reliable/known compression utility... –  Mar 29 '19 at 17:57
  • 1
    Also check if the Gzip file is actually concatenated Gzip. I don't know whether GZipStream can handle concatenated Gzip or not, but this might be a further possible problem scenario to check (if GZipStream would not be able to handle concatenated Gzip, it would only extract the first gzip stream in a concatenated gzip, which could possibly explain why you only get a fraction of the decompressed data) –  Mar 29 '19 at 17:58
  • I did manually download and decompress using gunzip in CygWin and the file was complete. Also I can see that the server sends the correct data as the file size matches. So I know the FTP portion of my code is OK. This may be a concatenated Gzip situation as the file is a zipped up log file that is added to every day and so grows to finally be a month's log. Also when I decompress in my code I see that in fact I only have one day's worth of log so I think you are correct in that it is a concatenated Gzip problem. Looks like it is known issue https://github.com/dotnet/corefx/issues/27279 – Matt M. Mar 29 '19 at 18:26

0 Answers0