简体   繁体   English

用于文件传输的C#远程流未读取

[英]C# remote stream for file transfer does not read

i have written a little "Update Programm" to keep an .exe up to date for the rest of my dev team. 我编写了一些“更新程序”,以使我的开发团队的其他成员保持.exe的最新状态。 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. GetVersion()仅返回.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. 我的streamRemote只是不返回任何字节,所以没有填充此while子句。

Any advice for me? 对我有什么建议吗?

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? Web服务器的配置是否发生任何更改,使您无法下载可执行文件?
  • Are you connecting through a proxy? 您是否通过代理进行连接?
  • Can you manually get to the same URL (under the same user credentials of your application)? 您可以手动访问相同的URL(在您的应用程序的相同用户凭据下)吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM