/// <summary> /// Initializes a new instance of the <see cref="FtpServer"/> class. /// </summary> /// <param name="serverOptions">The server options.</param> /// <param name="serviceProvider">The service provider used to query services.</param> /// <param name="controlStreamAdapters">Adapters for the control connection stream.</param> /// <param name="logger">The FTP server logger.</param> public FtpServer( IOptions <FtpServerOptions> serverOptions, IServiceProvider serviceProvider, IEnumerable <IFtpControlStreamAdapter> controlStreamAdapters, ILogger <FtpServer>?logger = null) { _serviceProvider = serviceProvider; _controlStreamAdapters = controlStreamAdapters.ToList(); _log = logger; ServerAddress = serverOptions.Value.ServerAddress; Port = serverOptions.Value.Port; MaxActiveConnections = serverOptions.Value.MaxActiveConnections; var tcpClientChannel = Channel.CreateBounded <TcpClient>(5); _serverListener = new FtpServerListenerService(tcpClientChannel, serverOptions, _serverShutdown, logger); _serverListener.ListenerStarted += (s, e) => { Port = e.Port; OnListenerStarted(e); }; _clientReader = ReadClientsAsync(tcpClientChannel, _serverShutdown.Token); if (serverOptions.Value.ConnectionInactivityCheckInterval is TimeSpan checkInterval) { _connectionTimeoutChecker = new Timer( _ => CloseExpiredConnections(), null, checkInterval, checkInterval); } }
/// <summary> /// Initializes a new instance of the <see cref="FtpServer"/> class. /// </summary> /// <param name="serverOptions">The server options.</param> /// <param name="serviceProvider">The service provider used to query services.</param> /// <param name="logger">The FTP server logger.</param> public FtpServer( [NotNull] IOptions <FtpServerOptions> serverOptions, [NotNull] IServiceProvider serviceProvider, [CanBeNull] ILogger <FtpServer> logger = null) { _serviceProvider = serviceProvider; _log = logger; ServerAddress = serverOptions.Value.ServerAddress; Port = serverOptions.Value.Port; MaxActiveConnections = serverOptions.Value.MaxActiveConnections; var tcpClientChannel = Channel.CreateBounded <TcpClient>(5); _serverListener = new FtpServerListenerService(tcpClientChannel, serverOptions, _serverShutdown, logger); _serverListener.ListenerStarted += (s, e) => { Port = e.Port; OnListenerStarted(e); }; _clientReader = ReadClientsAsync(tcpClientChannel, _serverShutdown.Token); }