用于文件传输的c#远程流不读取

本文关键字:程流不 读取 文件 传输 用于 | 更新日期: 2023-09-27 18:15:10

我写了一个小的"更新程序"来保持我的开发团队的其余的。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子句没有被填充。

有什么建议吗?

用于文件传输的c#远程流不读取

我认为问题出在服务器上。我要检查一下:

  • web服务器的配置是否更改了阻止您下载可执行文件?
  • 您是否通过代理连接?
  • 您可以手动访问相同的URL(在您的应用程序的相同用户凭据下)吗?