コード例 #1
0
        public void RemoveOnlineUser(FtpSession session, FtpUser user)
        {
            FtpUser onlineUser = null;

            lock (m_SyncRoot)
            {
                m_DictOnlineUser.TryGetValue(user.UserName, out onlineUser);
            }

            if (onlineUser != null)
            {
                if (onlineUser.DecreaseConnection() <= 0)
                {
                    lock (m_SyncRoot)
                    {
                        m_DictOnlineUser.Remove(user.UserName);
                    }

                    FtpServiceProvider.UpdateUsedSpaceForUser(user);
                }
            }
        }
コード例 #2
0
        private bool SetupFtpProvider(IRootConfig rootConfig, IServerConfig config)
        {
            var providerType     = config.Options.GetValue("ftpProviderType");
            var providerTypeName = config.Options.GetValue("ftpProviderName");

            if (string.IsNullOrEmpty(providerType) && string.IsNullOrEmpty(providerTypeName))
            {
                try
                {
                    var ftpProvider = new XmlFtpProvider();

                    if (!ftpProvider.Init(this, config))
                    {
                        return(false);
                    }

                    FtpServiceProvider = ftpProvider;
                    return(true);
                }
                catch (Exception e)
                {
                    if (Logger.IsErrorEnabled)
                    {
                        Logger.Error(e);
                    }

                    return(false);
                }
            }

            if (!string.IsNullOrEmpty(providerType) && !string.IsNullOrEmpty(providerTypeName))
            {
                if (Logger.IsErrorEnabled)
                {
                    Logger.Error("You cannot have both ftpProviderType and ftpProviderName configured!");
                }

                return(false);
            }

            if (!string.IsNullOrEmpty(providerTypeName))
            {
                var providers = rootConfig.GetChildConfig <TypeProviderCollection>("ftpProviders");

                if (providers == null || providers.Count == 0)
                {
                    if (Logger.IsErrorEnabled)
                    {
                        Logger.Error("Configuration node ftpProviders is required!");
                    }

                    return(false);
                }

                var typeProvider = providers.OfType <TypeProvider>().FirstOrDefault(p =>
                                                                                    providerTypeName.Equals(p.Name, StringComparison.OrdinalIgnoreCase));

                if (typeProvider == null)
                {
                    if (Logger.IsErrorEnabled)
                    {
                        Logger.ErrorFormat("The ftp provider {0} was not found!", providerTypeName);
                    }

                    return(false);
                }

                providerType = typeProvider.Type;
            }


            Type realProviderType;

            try
            {
                realProviderType   = Type.GetType(providerType, true);
                FtpServiceProvider = (FtpServiceProviderBase)Activator.CreateInstance(realProviderType);
            }
            catch (Exception e)
            {
                if (Logger.IsErrorEnabled)
                {
                    Logger.Error(e);
                }

                return(false);
            }

            return(FtpServiceProvider.Init(this, config));
        }