예제 #1
0
파일: FtpItem.cs 프로젝트: ychsu/YC.FTP
        private FtpItem DosParser(Match m)
        {
            var     isDir    = m.Groups[2].Success;
            var     fullName = FullName.TrimEnd('/');
            var     fileName = m.Groups["FileName"].Value.Trim();
            FtpItem item     = isDir ?
                               new FtpDirectory(Client, fullName + "/" + fileName, this.encoding) as FtpItem :
                               new FtpFile(Client, fullName + "/" + fileName, this.encoding) as FtpItem;

            item.Exists = true;
            if (m.Groups[nameof(item.FileSize)].Success == true)
            {
                int size;
                if (int.TryParse(m.Groups[nameof(item.FileSize)].Value.Trim(), out size) == true)
                {
                    item.FileSize = size;
                }
            }
            if (m.Groups[nameof(item.ModifiedOn)].Success == true)
            {
                DateTime i;
                var      str      = m.Groups[nameof(item.ModifiedOn)].Value.Trim();
                var      provider = System.Globalization.CultureInfo.GetCultureInfo("en-US");
                if (DateTime.TryParseExact(str, "MM-dd-yy hh:mmtt", provider, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out i) == true)
                {
                    item.ModifiedOn = i;
                }
            }
            return(item);
        }
예제 #2
0
파일: FtpItem.cs 프로젝트: ychsu/YC.FTP
        private FtpItem UnixParser(Match m)
        {
            var     permissions = m.Groups["Permissions"].Value.ToLower().Trim();
            var     fullName    = FullName.TrimEnd('/');
            var     fileName    = m.Groups["FileName"].Value.Trim();
            FtpItem item        = permissions[0] == 'd' ?
                                  new FtpDirectory(this.Client, fullName + "/" + fileName, this.encoding) as FtpItem :
                                  new FtpFile(Client, fullName + "/" + fileName, this.encoding) as FtpItem;

            item.Exists      = true;
            item.Permissions = permissions;
            item.Owner       = m.Groups[nameof(item.Owner)].Value.Trim();
            item.Group       = m.Groups[nameof(item.Group)].Value.Trim();
            if (m.Groups[nameof(item.FileSize)].Success == true)
            {
                int i;
                if (int.TryParse(m.Groups[nameof(item.FileSize)].Value.Trim(), out i) == true)
                {
                    item.FileSize = i;
                }
            }
            if (m.Groups[nameof(item.ModifiedOn)].Success == true)
            {
                var formats = new string[]
                {
                    "MMM d HH:mm",
                    "MMM d yyyy"
                };
                var      provider = System.Globalization.CultureInfo.GetCultureInfo("en-US");
                DateTime i;
                if (DateTime.TryParseExact(m.Groups[nameof(item.ModifiedOn)].Value.Trim(), formats, provider, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out i) == true)
                {
                    item.ModifiedOn = i;
                }
            }
            return(item);
        }