8,497
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// Gets the files or directories from the specified directory.
/// </summary>
/// <param name="directory">The directory.</param>
/// <param name="type">The type.</param>
/// <returns>
/// An enumeration of <see cref="FlagFtp.FtpFileSystemInfo"/> with the type of the specified type argument.
/// </returns>
private IEnumerable<FtpFileSystemInfo> GetFileSystemInfos(Uri directory, FtpFileSystemInfoType type)
{
if (directory == null)
throw new ArgumentNullException("directory");
if (directory.Scheme != Uri.UriSchemeFtp)
throw new ArgumentException("The directory isn't a valid FTP URI", "directory");
using (var response = (this.CreateResponse(directory, WebRequestMethods.Ftp.ListDirectoryDetails)))
{
using (Stream responseStream = response.GetResponseStream())
{
using (var reader = new StreamReader(responseStream))
{
string all = reader.ReadToEnd();
//这个正则没大看懂。
var regex = new Regex(@"^(?<FileOrDirectory>[d-])(?<Attributes>[rwxts-]{3}){3}\s+\d{1,}\s+.*?(?<FileSize>\d{1,})\s+(?<Date>\w+\s+\d{1,2}\s+(?:\d{4})?)(?<YearOrTime>\d{1,2}:\d{2})?\s+(?<Name>.+?)\s?$",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
MatchCollection matches = regex.Matches(all);
var infos = matches.Cast<Match>()
.Select(
match =>
new
{
IsDirectory = match.Groups["FileOrDirectory"].Value == "d",