FTPWebRequest:下载 GZipped 文件时遇到问题

发布于 2024-09-14 06:52:27 字数 470 浏览 2 评论 0原文

我正在使用 System.NET.FtpWebRequest 下载使用 GZip 压缩的 xml 文件。

我收到的文件大约是服务器上文件大小的两倍,而 System.IO.Compression.GZipStream 不喜欢它们。它返回以下错误消息:

System.IO.InvalidDataException : 
The magic number in GZip header is not correct. 
Make sure you are passing in a GZip stream.

GZip 网站表明许多问题是由将二进制文件下载为 ASCII 引起的。但是,无论我在 FtpWebRequest 上将 UseBinary 设置为 true 还是 false,我都会遇到同样的问题。

我的解压代码在使用 FileZilla 手动下载的文件上运行良好。

像往常一样,我们非常感谢您的帮助。

I'm downloading xml files that are compressed using GZip using System.NET.FtpWebRequest.

The files I receive are about twice the size as the files on the server and System.IO.Compression.GZipStream does not like them. It returns the following error message:

System.IO.InvalidDataException : 
The magic number in GZip header is not correct. 
Make sure you are passing in a GZip stream.

The GZip web site suggests many problems are caused by downloading binary files as ASCII. However, I'm getting the same problem whether I set UseBinary to true or false on FtpWebRequest.

My decompression code runs fine on files manually downloaded with FileZilla.

As usual your help is greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥醉 2024-09-21 06:52:27

我的不好。问题在于我如何将流保存到磁盘。 FtpWebRequest 或 GZip 根本不是问题。正在使用 StreamWriter 来处理文本文件(我继承了那篇文章)。将 FtpResponse 流写入 FileStream 解决了我的问题。

感谢您的浏览;很抱歉浪费了任何人的时间。

My bad. The problem is with how I'm saving the stream to disk. Not a problem with FtpWebRequest or GZip at all. Was using a StreamWriter to a text file (I inherited that piece). Writing the FtpResponse stream to a FileStream solves my issue.

Thanks for looking; sorry for wasting anyone's time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文