Ejemplo n.º 1
0
        public FtpClient(string url, string userName, string password)
        {
            if (!url.StartsWith("ftp://", StringComparison.InvariantCultureIgnoreCase)) url = "ftp://" + url;
            this.url = url;
            this.userName = userName;
            this.password = password;

            Root = new FileItem();
            Root.Permissions = "d";
            Root.ftp = this;
        }
Ejemplo n.º 2
0
        internal static FileItem Parse(FtpClient ftp, string parentFolder, string data)
        {
            string pattern = @"
            ^                       # Beginning Anchor
            (?<Permissions>[^\s]+)  # Get permissions into named capture
            (?:\s+)                 # Match but don't capture space
            (?<Count>\d+)
            (?:\s+)
            (?<Op1>[^\s]+)          # Continue with capturing valued text into named
            (?:\s+)                 # captures and matching, but not capturing space which is ignored.
            (?<Op2>[^\s]+)
            (?:\s+)
            (?<Size>[^\s]+)
            (?:\s+)
            (?<Month>[^\s]+)
            (?:\s+)
            (?<Day>[^\s]+)
            (?:\s+)
            (?<Year>[^\s]+)
            (?:\s+)
            (?<FileName>[^\r\n]+)";

            // Ignore option only applies to the pattern so we can comment it.
            var mtGroup = Regex.Match(data, pattern, RegexOptions.IgnorePatternWhitespace).Groups;

            FileItem fi = new FileItem();
            fi.Permissions = mtGroup["Permissions"].Value;
            fi.Count = int.Parse(mtGroup["Count"].Value);
            fi.Permissions = mtGroup["Permissions"].Value;
            fi.Op1 = mtGroup["Op1"].Value;
            fi.Op2 = mtGroup["Op2"].Value;
            fi.Size = long.Parse(mtGroup["Size"].Value);
            fi.Month = mtGroup["Month"].Value;
            fi.Day = mtGroup["Day"].Value;
            fi.Year = mtGroup["Year"].Value;
            fi.FileName = mtGroup["FileName"].Value;

            fi.ParentFolder = parentFolder;

            fi.ftp = ftp;

            return fi;
        }