Пример #1
0
        /// <summary>
        /// 获取当前目录下指定目录下的文件和一级子目录信息
        /// </summary>
        /// <param name="directory">如未指定目录,则启用默认目录</param>
        /// <returns></returns>
        private (bool code, List <FileStruct> FileList) FindFilesByCurrentDirectories(string directory = "")
        {
            //必须保留最后的[/]符号,不然给出的列表会是带有directory/fileName这样的结果
            string uri  = directory.Length == 0 ? _ftpUri : $"{_ftpUri}/{directory}/";
            var    res1 = FindFilesAndDirectories(uri, WebRequestMethods.Ftp.ListDirectory);
            var    res2 = FindFilesAndDirectories(uri, WebRequestMethods.Ftp.ListDirectoryDetails);


            var fileList = new List <FileStruct>();

            foreach (var name in res1.FileList)
            {
                string line = res2.FileList.FirstOrDefault(x => x.Contains(name)) ?? "";
                if (line.Length > 0)
                {
                    if (_fileListStyle == FileListStyle.Unknown || line == "")
                    {
                        continue;
                    }
                    FileStruct f = new FileStruct
                    {
                        Name     = name,
                        FullName = directory.Length > 0 ? $"{directory}/{name}" : name
                    };
                    switch (_fileListStyle)
                    {
                    case FileListStyle.UnixStyle: ParseFileStructFromUnixStyleRecord(line, ref f); break;

                    case FileListStyle.WindowsStyle: ParseFileStructFromWindowsStyleRecord(line, ref f); break;
                    }
                    fileList.Add(f);
                }
            }
            if (res2.FileList.Count > 0)
            {
                res2.FileList = res2.FileList.Select(x => $"{directory}/{x}").ToList();
                Nlog.Info(_nlogName, $"\r\n{string.Join("\r\n", res2.FileList)}");
            }
            return(res1.code && res2.code, fileList);
        }