public override bool Init(FtpServer server, IServerConfig config)
        {
            if (!base.Init(server, config))
            {
                return(false);
            }

            var userSettingFile = config.Options.GetValue("userSetting");

            if (string.IsNullOrEmpty(userSettingFile))
            {
                server.Logger.Error("No user setting file was not defined!");
                return(false);
            }

            if (!Path.IsPathRooted(userSettingFile))
            {
                userSettingFile = server.GetFilePath(userSettingFile);
            }

            if (!File.Exists(userSettingFile))
            {
                AppServer.Logger.Error("The userSetting file cannot be found!");
                return(false);
            }

            m_UserConfigFile = userSettingFile;

            ReadUserConfigFile();

            m_UserConfigReadTimer = new Timer(OnUserConfigReadTimerCallback, null, Timeout.Infinite, Timeout.Infinite);

            return(true);
        }
Ejemplo n.º 2
0
        public override bool Init(FtpServer server, IServerConfig config)
        {
            if (!base.Init(server, config))
            {
                return(false);
            }

            var userSettingFile = config.Options.GetValue("userSetting");

            if (string.IsNullOrEmpty(userSettingFile))
            {
                server.Logger.Error("No user setting file defined!");
                return(false);
            }

            List <FtpUser> users;

            try
            {
                users = XmlSerializerUtil.Deserialize <List <FtpUser> >(server.GetFilePath(userSettingFile));
            }
            catch (Exception e)
            {
                AppServer.Logger.Error("Failed to deserialize FtpUser list file!", e);
                return(false);
            }

            m_UserDict = users.ToDictionary(u => u.UserName, u => u, StringComparer.OrdinalIgnoreCase);

            return(true);
        }
        public virtual bool Init(FtpServer server, IServerConfig config)
        {
            AppServer = server;

            var dataPortNode = config.Options.GetValue("dataPort");

            if (string.IsNullOrEmpty(dataPortNode))
            {
                server.Logger.Error("Parameter 'dataPort' is required!");
                return(false);
            }

            string[] range = dataPortNode.Split(',', ';', ':');

            for (int i = 0; i < range.Length; i++)
            {
                string portField = range[i];

                if (string.IsNullOrEmpty(portField))
                {
                    continue;
                }

                string[] arrPorts = portField.Split('-');

                if (arrPorts == null || arrPorts.Length < 1 || arrPorts.Length > 2)
                {
                    server.Logger.Error("Invalid 'dataPort' value in parameter!");
                    return(false);
                }

                if (arrPorts.Length == 1)
                {
                    int port;

                    if (!int.TryParse(arrPorts[0], out port))
                    {
                        server.Logger.Error("Invalid 'dataPort' value in parameter!");
                        return(false);
                    }

                    m_DataPorts.Add(port);
                }
                else if (arrPorts.Length == 2)
                {
                    int portStart, portEnd;

                    if (!int.TryParse(arrPorts[0], out portStart))
                    {
                        server.Logger.Error("Invalid 'dataPort' value in parameter!");
                        return(false);
                    }

                    if (!int.TryParse(arrPorts[1], out portEnd))
                    {
                        server.Logger.Error("Invalid 'dataPort' value in parameter!");
                        return(false);
                    }

                    if (portEnd <= portStart)
                    {
                        server.Logger.Error("Invalid 'dataPort' value in parameter!");
                        return(false);
                    }

                    if (portStart < 0)
                    {
                        portStart = 1;
                    }

                    if (portEnd > 65535)
                    {
                        portEnd = 65535;
                    }

                    for (int seq = portStart; seq < portEnd + 1; seq++)
                    {
                        m_DataPorts.Add(seq);
                    }
                }
            }

            return(true);
        }