Beispiel #1
0
        /// <summary>
        /// Parse raw file from server into a file object, using the currently active parser.
        /// </summary>
        public FtpListItem ParseSingleLine(string path, string file, List <FtpCapability> caps, bool isMachineList)
        {
            FtpListItem result = null;

            // force machine listing if it is
            if (isMachineList)
            {
                result = FtpMachineListParser.Parse(file, caps, client);
            }
            else
            {
                // use custom parser if given
                if (m_customParser != null)
                {
                    result = m_customParser(file, caps, client);
                }
                else
                {
                    if (IsWrongParser())
                    {
                        ValidateParser(new[] { file });
                    }

                    // use one of the in-built parsers
                    switch (CurrentParser)
                    {
                    case FtpParser.Legacy:
                        result = ParseLegacy(path, file, caps, client);
                        break;

                    case FtpParser.Machine:
                        result = FtpMachineListParser.Parse(file, caps, client);
                        break;

                    case FtpParser.Windows:
                        result = FtpWindowsParser.Parse(client, file);
                        break;

                    case FtpParser.Unix:
                        result = FtpUnixParser.Parse(client, file);
                        break;

                    case FtpParser.UnixAlt:
                        result = FtpUnixParser.ParseUnixAlt(client, file);
                        break;

                    case FtpParser.VMS:
                        result = FtpVMSParser.Parse(client, file);
                        break;

                    case FtpParser.IBM:
                        result = FtpIBMParser.Parse(client, file);
                        break;

                    case FtpParser.NonStop:
                        result = FtpNonStopParser.Parse(client, file);
                        break;
                    }
                }
            }

            // if parsed file successfully
            if (result != null)
            {
                // apply time difference between server/client
                if (HasTimeOffset)
                {
                    result.Modified = result.Modified - TimeOffset;
                }

                // calc absolute file paths
                result.CalculateFullFtpPath(client, path, false);
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Parse raw file from server into a file object, using the currently active parser.
        /// </summary>
        public FtpListItem ParseSingleLine(string path, string file, List <FtpCapability> caps, bool isMachineList)
        {
            FtpListItem result = null;

            // force machine listing if it is
            if (isMachineList)
            {
                result = FtpMachineListParser.Parse(file, caps, client);
            }
            else
            {
                // use custom parser if given
                if (CurrentParser == FtpParser.Custom && client.ListingCustomParser != null)
                {
                    result = client.ListingCustomParser(file, caps, client);
                }
                else
                {
                    if (IsWrongParser())
                    {
                        ValidateParser(new[] { file });
                    }

                    // use one of the in-built parsers
                    switch (CurrentParser)
                    {
                    case FtpParser.Machine:
                        result = FtpMachineListParser.Parse(file, caps, client);
                        break;

                    case FtpParser.Windows:
                        result = FtpWindowsParser.Parse(client, file);
                        break;

                    case FtpParser.Unix:
                        result = FtpUnixParser.Parse(client, file);
                        break;

                    case FtpParser.UnixAlt:
                        result = FtpUnixParser.ParseUnixAlt(client, file);
                        break;

                    case FtpParser.VMS:
                        result = FtpVMSParser.Parse(client, file);
                        break;

                    case FtpParser.IBM:
                        result = FtpIBMParser.Parse(client, file);
                        break;

                    case FtpParser.NonStop:
                        result = FtpNonStopParser.Parse(client, file);
                        break;
                    }
                }
            }

            // if parsed file successfully
            if (result != null)
            {
                // process created date into the timezone required
                result.RawCreated = result.Created;
                if (result.Created != DateTime.MinValue)
                {
                    result.Created = client.ConvertDate(result.Created);
                }

                // process modified date into the timezone required
                result.RawModified = result.Modified;
                if (result.Modified != DateTime.MinValue)
                {
                    result.Modified = client.ConvertDate(result.Modified);
                }

                // calc absolute file paths
                result.CalculateFullFtpPath(client, path, false);
            }

            return(result);
        }