Exemplo n.º 1
0
        private void DownloadDirectory(object o)
        {
            string pathname = o as string;

            //获取当前目录所有文件
            GetFilesItem gfi = new GetFilesItem
            {
                Target = _dc.GetFtpPathfile(pathname)
            };

            _dc.Execute(gfi);
            if (gfi.Success == false)
            {
                Notified?.Invoke(CVRDownloadResult.SourceHappened, gfi.Target);
                return;
            }

            foreach (FileInfoItem fii in gfi.Files)
            {
                if (_excludedItems.Contains(fii.Name))
                {
                    continue;
                }

                string           remote = _dc.GetFtpPathfile(Path.Combine(pathname, fii.Name));
                DownloadDataItem ddi    = new DownloadDataItem
                {
                    Source = remote,
                    Target = _dc.GetDrivePathfile(Path.Combine(_temp, Path.Combine(pathname, fii.Name)))
                };

                string dir = (new FileInfo(ddi.Target)).DirectoryName;
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                _requestedCount++;
                _dc.Add(ddi);
            }

            //获取当前目录所有子目录
            GetDirectoriesItem gdi = new GetDirectoriesItem
            {
                Target = _dc.GetFtpPathfile(pathname)
            };

            _dc.Execute(gdi);

            foreach (FileInfoItem fii in gdi.Directories)
            {
                DownloadDirectory(Path.Combine(pathname, fii.Name));
            }
        }