尝试下载局域网上的文件,文件夹和文件都有,但是文件是空文件,请问是什么原因?

尝试下载局域网上的文件,循环下载,文件夹和文件都有了,但是文件都是4KB内容相同,而且Log显示文件长度都是一样的。我尝试用这个方法下载本地的文件,就能很顺利的下载下来。有人知道是什么原因么?

 /// <summary>
        /// 下载文件夹下的所有文件,安装到指定的路径下
        /// </summary>
        /// <param name="downloadPath">下载地址</param>
        /// <param name="savePath">保存地址</param>
        /// <param name="LoadProgress">加载进度条</param>
        /// <param name="DownLoad">加载完成事件</param>
        /// <returns></returns>
        public IEnumerator DownLoadAllAssetByWeb(string downloadPath, string savePath, Action<int, int> LoadProgress, Action DownLoad = null)
        {
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }

            //修改文件路径名称
            downloadPath = UrlAdjustment(downloadPath);

            Debug.Log(downloadPath);

            //得到所有的文件件路径和所有文件的路径
            getSourceFolder(downloadPath);

            Debug.Log("文件的数量:"+fileVessel.Count);

            int allFileCount = fileVessel.Count;
            int currentDownloadCount = 0;

            //新建文件夹
            for (int i = 0; i < folderVessel.Count; i++)
            {
                string tp = folderVessel[i].Replace(downloadPath, savePath);
                Directory.CreateDirectory(tp);
            }

            //循环下载
            for (int i = 0; i < fileVessel.Count; i++)
            {
                currentDownloadCount = i;

                string installUrl = fileVessel[i].Replace(downloadPath, savePath);

                Debug.Log("加载的路径:" + fileVessel[i]); //
                Debug.Log("安装的路径:" + installUrl);  //

                UnityWebRequest request = UnityWebRequest.Get(fileVessel[i]);

                yield return request.SendWebRequest();

                if (request.isNetworkError || request.isHttpError)
                {
                    Debug.Log("Download Error:" + request.error);
                }
                else if (request.isDone)
                {
                    byte[] results = request.downloadHandler.data;

                    Debug.Log("资源长度:" + results.Length);  //长度都是相同的

                    FileInfo fileInfo = new FileInfo(installUrl);
                    FileStream fs = fileInfo.Create();

                    //FileStream fs = new FileStream(installUrl, FileMode.Create);

                    //fs.Write(字节数组, 开始位置, 数据长度);
                    fs.Write(results, 0, results.Length);
                    fs.Flush(); //文件写入存储到硬盘
                    fs.Close(); //关闭文件流对象
                    fs.Dispose(); //销毁文件对象
                }

                if (LoadProgress != null)
                {
                    LoadProgress(currentDownloadCount, allFileCount);
                }

                request.Dispose();
            }

            yield return 0;


            if (DownLoad != null)
                DownLoad();
        }


```c#

        void getSourceFolder(string folder)
        {
            getSourceFile(folder);
            DirectoryInfo di = new DirectoryInfo(folder);
            foreach (DirectoryInfo subDir in di.GetDirectories())
            {
                string newFloder = folder + "/" + subDir.Name; 
                folderVessel.Add(newFloder);
                getSourceFolder(newFloder);
            }
        }

        void getSourceFile(string path)
        {
            string newString = null;

            foreach (string subDir in Directory.GetFiles(path))
            {
                newString = subDir.Replace('\\', '/');
                fileVessel.Add(newString);
            }
        }

```

img

img

压缩一下,然后再下载,你试一试,应该是可以

文件都是4KB内容相同
打开你的文件看看
是不是一些html,里面包含了某个错误信息