C# 文件传输的远程流不读取

发布于 2024-12-17 04:50:10 字数 1859 浏览 0 评论 0原文

我编写了一些“更新程序”,以使 .exe 为我的开发团队的其他成员保持最新状态。以前工作正常,但突然就停止工作了。

我已经注意到这个问题:我的远程流无法开始读取。

        Uri patch = new Uri("http://********/*********/" + GetVersion().ToString() + ".exe");
        Int64 patchsize = PatchSize(patch);
        var CurrentPath = String.Format("{0}\\", Environment.CurrentDirectory);
        Int64 IntSizeTotal = 0;
        Int64 IntRunning = 0;
        string strNextPatch = (version + ".exe");

        using (System.Net.WebClient client = new System.Net.WebClient())
        {
            using (System.IO.Stream streamRemote = client.OpenRead(patch))
            {
                using (System.IO.Stream streamLocal = new FileStream(CurrentPath + strNextPatch, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    int intByteSize = 0;

                    byte[] byteBuffer = new Byte[IntSizeTotal];

                    while ((intByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)
                    {
                        streamLocal.Write(byteBuffer, 0, intByteSize);

                        IntRunning += intByteSize;

                        double dIndex = (double)(IntRunning);
                        double dTotal = (double)byteBuffer.Length;
                        double dProgressPercentage = (dIndex / dTotal);
                        int intProgressPercentage = (int)(dProgressPercentage * 100);

                        worker.ReportProgress(intProgressPercentage);
                    }
                    streamLocal.Close();
                }
                streamRemote.Close();

GetVersion() 仅返回 .exe 的当前服务器版本的当前版本号。 问题出在这里:

while ((intByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)

我的streamRemote 只是不返回任何字节,因此这个while 子句没有被填充。

对我有什么建议吗?

i have written a little "Update Programm" to keep an .exe up to date for the rest of my dev team. It used to work fine, but suddenly it stopped working.

I already noticed the problem: my remote stream does not start to read.

        Uri patch = new Uri("http://********/*********/" + GetVersion().ToString() + ".exe");
        Int64 patchsize = PatchSize(patch);
        var CurrentPath = String.Format("{0}\\", Environment.CurrentDirectory);
        Int64 IntSizeTotal = 0;
        Int64 IntRunning = 0;
        string strNextPatch = (version + ".exe");

        using (System.Net.WebClient client = new System.Net.WebClient())
        {
            using (System.IO.Stream streamRemote = client.OpenRead(patch))
            {
                using (System.IO.Stream streamLocal = new FileStream(CurrentPath + strNextPatch, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    int intByteSize = 0;

                    byte[] byteBuffer = new Byte[IntSizeTotal];

                    while ((intByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)
                    {
                        streamLocal.Write(byteBuffer, 0, intByteSize);

                        IntRunning += intByteSize;

                        double dIndex = (double)(IntRunning);
                        double dTotal = (double)byteBuffer.Length;
                        double dProgressPercentage = (dIndex / dTotal);
                        int intProgressPercentage = (int)(dProgressPercentage * 100);

                        worker.ReportProgress(intProgressPercentage);
                    }
                    streamLocal.Close();
                }
                streamRemote.Close();

GetVersion() only returns the current version number of the current server version of the .exe.
The problem lies here:

while ((intByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)

My streamRemote just does not return any bytes so this while clause is not filled.

Any advice for me?

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

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

发布评论

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

评论(1

白昼 2024-12-24 04:50:10

我相信问题出在服务器上。我会运行一些检查:

  • Web 服务器的配置是否发生了任何更改,导致您无法下载可执行文件?
  • 您是通过代理连接吗?
  • 您可以手动访问相同的 URL(在应用程序的相同用户凭据下)吗?

I believe the problem is on the server. I'd run some checks:

  • Has anything changed on the configuration of the web server that stops you from downloading executables?
  • Are you connecting through a proxy?
  • Can you manually get to the same URL (under the same user credentials of your application)?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文