/// <summary>
        ///		Interpreta la línea
        /// </summary>
        protected override FtpEntry ParseLine(string pathLine, FtpPath pathParent)
        {
            FtpEntry entry = null;
            Match    match = RegExWindows.Match(pathLine);

            // Interpreta la línea
            if (match.Success)
            {
                string   name              = match.Groups["name"].Value;
                DateTime createdAt         = ParseDateTime(match);
                string   strLiteralSize    = match.Groups["size"].Value;
                long     size              = 0;
                FtpEntry.FtpEntryType type = FtpEntry.FtpEntryType.File;

                // Obtiene el tamaño del archivo. Si no tiene tamaño, se le considera un directorio
                if (!string.IsNullOrEmpty(strLiteralSize))
                {
                    size = long.Parse(strLiteralSize);
                }
                else
                {
                    type = FtpEntry.FtpEntryType.Directory;
                }
                // Obtine la entrada
                entry = new FtpEntry(pathParent, name, size, type, createdAt, null);
            }
            // Devuelve la entrada
            return(entry);
        }
Esempio n. 2
0
        /// <summary>
        ///		Añade un archivo a la colección interpretando la línea
        /// </summary>
        /// <remarks>
        ///		El formato de la línea de archivo es: type=file;modify=20160428102907;size=1695961; 2016.04.28.12.29.06.493.pdf
        ///		Es decir [fact=value]* Space FileName
        ///		Donde fact: "Size" / "Modify" / "Create" / "Type" / "Unique" / "Perm" / "Lang" / "Media-Type" / "CharSet" /
        /// </remarks>
        private void AddFileEntry(string file)
        {
            if (!string.IsNullOrWhiteSpace(file))
            {
                string[] parts             = file.Split(';');
                string   fileName          = "";
                FtpEntry.FtpEntryType type = FtpEntry.FtpEntryType.File;
                long     size = 0;
                DateTime updatedAt = DateTime.MinValue, createdAt = DateTime.MinValue;

                // Obtiene los datos del archivo de la cadena
                for (int index = 0; index < parts.Length; index++)
                {
                    if (!string.IsNullOrEmpty(parts[index]))
                    {
                        // Limpia los espacios
                        parts[index] = parts[index].Trim();
                        // Asigna el valor adecuado para la entrada
                        if (index == parts.Length - 1)
                        {
                            fileName = parts[index];
                        }
                        else
                        {
                            string[] values = parts[index].Split('=');

                            if (values.Length == 2 && !string.IsNullOrEmpty(values[0]) &&
                                !string.IsNullOrEmpty(values[1]))
                            {
                                // Limpia los espacios
                                values[0] = values[0].Trim();
                                values[1] = values[1].Trim();
                                // Obtiene el valor adecuado
                                if (values[0].Equals("Size", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    size = ParseLong(values[1]);
                                }
                                else if (values[0].Equals("Type", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    type = GetFileType(values[1]);
                                }
                                else if (values[0].Equals("Modify", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    updatedAt = ParseDate(values[1]);
                                }
                                else if (values[1].Equals("Create", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    createdAt = ParseDate(values[1]);
                                }
                            }
                        }
                    }
                }
                // Añade el archivo a la colección
                if (!string.IsNullOrEmpty(fileName))
                {
                    Files.Add(new FtpEntry(Path, fileName, size, type, updatedAt, null));
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        ///		Interpreta una línea en formato Unix
        /// </summary>
        protected virtual FtpEntry ParseLine(string pathLine, FtpPath pathParent)
        {
            FtpEntry entry = null;
            Match    match = RegExUnix.Match(pathLine);

            // Obtiene los datos de la línea
            if (match.Success)
            {
                string extendedType        = match.Groups["xtype"].Value;
                string name                = match.Groups["name"].Value;
                FtpEntry.FtpEntryType type = FtpEntry.FtpEntryType.File;
                string target              = null;

                // Obtiene los datos de la entrada
                if (string.Equals(extendedType, "d", StringComparison.InvariantCultureIgnoreCase))
                {
                    type = FtpEntry.FtpEntryType.Directory;
                }
                else if (string.Equals(extendedType, "l", StringComparison.InvariantCultureIgnoreCase))
                {
                    // Indica que es un vínculo
                    type = FtpEntry.FtpEntryType.Link;
                    // Separa el nombre del vínculo
                    SepareLink(ref name, ref target);
                }
                // Crea el objeto con los datos de la entrada
                entry = new FtpEntry(pathParent, name, long.Parse(match.Groups["size"].Value), type,
                                     ParseDateTime(match), target);
            }
            // Devuelve la entrada del directorio
            return(entry);
        }