Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FtpServer"/> class.
 /// </summary>
 /// <param name="fileSystemClassFactory">The <see cref="IFileSystemClassFactory"/> to use to create the <see cref="IUnixFileSystem"/> for the logged in user.</param>
 /// <param name="membershipProvider">The <see cref="IMembershipProvider"/> used to validate a login attempt</param>
 /// <param name="serverAddress">The public IP address (required for <code>PASV</code> and <code>EPSV</code>)</param>
 /// <param name="port">The port of the FTP server (usually 21)</param>
 /// <param name="handlerFactory">The handler factories to create <see cref="FtpCommandHandler"/> and <see cref="FtpCommandHandlerExtension"/> instances for new <see cref="FtpConnection"/> objects</param>
 public FtpServer([NotNull] IFileSystemClassFactory fileSystemClassFactory, [NotNull] IMembershipProvider membershipProvider, [NotNull] string serverAddress, int port, [NotNull, ItemNotNull] IFtpCommandHandlerFactory handlerFactory)
 {
     ServerAddress          = serverAddress;
     DefaultEncoding        = Encoding.UTF8;
     OperatingSystem        = "UNIX";
     FileSystemClassFactory = fileSystemClassFactory;
     MembershipProvider     = membershipProvider;
     Port = port;
     CommandsHandlerFactory   = handlerFactory;
     BackgroundTransferWorker = new BackgroundTransferWorker(this);
     BackgroundTransferWorker.Start(_cancellationTokenSource);
 }
Ejemplo n.º 2
0
 /// <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>
 /// <param name="loggerFactory">Factory for loggers.</param>
 public FtpServer(
     [NotNull] IOptions <FtpServerOptions> serverOptions,
     [NotNull] IServiceProvider serviceProvider,
     [CanBeNull] ILogger <FtpServer> logger   = null,
     [CanBeNull] ILoggerFactory loggerFactory = null)
 {
     _serviceProvider         = serviceProvider;
     _log                     = logger;
     ServerAddress            = serverOptions.Value.ServerAddress;
     Port                     = serverOptions.Value.Port;
     BackgroundTransferWorker = new BackgroundTransferWorker(loggerFactory?.CreateLogger <BackgroundTransferWorker>());
     BackgroundTransferWorker.Start(_cancellationTokenSource);
 }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public void Dispose()
        {
            if (!Stopped)
            {
                Stop();
            }

            try
            {
                _listenerTask.GetAwaiter().GetResult();
            }
            catch (TaskCanceledException)
            {
                // Ignorieren - alles ist OK
            }

            BackgroundTransferWorker.Dispose();
            _cancellationTokenSource.Dispose();
            _listenerTaskEvent.Dispose();
            _connections.Dispose();
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public void Dispose()
        {
            if (!Stopped)
            {
                Stop();
            }

            try
            {
                _listenerTask.GetAwaiter().GetResult();
            }
            catch (TaskCanceledException)
            {
                // Ignorieren - alles ist OK
            }

            BackgroundTransferWorker.Dispose();
            _cancellationTokenSource.Dispose();
            foreach (var connectionInfo in _connections.Values)
            {
                connectionInfo.Scope.Dispose();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Enqueue a new <see cref="IBackgroundTransfer"/> for the given <paramref name="connection"/>
        /// </summary>
        /// <param name="backgroundTransfer">The background transfer to enqueue</param>
        /// <param name="connection">The connection to enqueue the background transfer for</param>
        public void EnqueueBackgroundTransfer([NotNull] IBackgroundTransfer backgroundTransfer, [CanBeNull] FtpConnection connection)
        {
            var entry = new BackgroundTransferEntry(backgroundTransfer, connection?.Log);

            BackgroundTransferWorker.Enqueue(entry);
        }
Ejemplo n.º 6
0
 public IReadOnlyCollection <Tuple <string, BackgroundTransferStatus> > GetBackgroundTaskStates()
 {
     return(BackgroundTransferWorker.GetStates());
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FtpServer"/> class.
 /// </summary>
 /// <param name="fileSystemClassFactory">The <see cref="IFileSystemClassFactory"/> to use to create the <see cref="IUnixFileSystem"/> for the logged in user.</param>
 /// <param name="membershipProvider">The <see cref="IMembershipProvider"/> used to validate a login attempt</param>
 /// <param name="serverAddress">The public IP address (required for <code>PASV</code> and <code>EPSV</code>)</param>
 /// <param name="port">The port of the FTP server (usually 21)</param>
 /// <param name="handlerFactory">The handler factories to create <see cref="FtpCommandHandler"/> and <see cref="FtpCommandHandlerExtension"/> instances for new <see cref="FtpConnection"/> objects</param>
 public FtpServer([NotNull] IFileSystemClassFactory fileSystemClassFactory, [NotNull] IMembershipProvider membershipProvider, [NotNull] string serverAddress, int port, [NotNull, ItemNotNull] IFtpCommandHandlerFactory handlerFactory)
 {
     ServerAddress = serverAddress;
     DefaultEncoding = Encoding.UTF8;
     OperatingSystem = "UNIX";
     FileSystemClassFactory = fileSystemClassFactory;
     MembershipProvider = membershipProvider;
     Port = port;
     CommandsHandlerFactory = handlerFactory;
     BackgroundTransferWorker = new BackgroundTransferWorker(this);
     BackgroundTransferWorker.Start(_cancellationTokenSource);
 }
Ejemplo n.º 8
0
        /// <inheritdoc />
        public void EnqueueBackgroundTransfer(IBackgroundTransfer backgroundTransfer, IFtpConnection connection)
        {
            var entry = new BackgroundTransferEntry(backgroundTransfer, connection?.Log);

            BackgroundTransferWorker.Enqueue(entry);
        }
Ejemplo n.º 9
0
 /// <inheritdoc />
 public IReadOnlyCollection <BackgroundTransferInfo> GetBackgroundTaskStates()
 {
     return(BackgroundTransferWorker.GetStates());
 }