Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PauseConnectionServerCommandHandler"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The FTP connection accessor.</param>
 /// <param name="logger">The logger.</param>
 public PauseConnectionServerCommandHandler(
     [NotNull] IFtpConnectionAccessor connectionAccessor,
     [CanBeNull] ILogger <PauseConnectionServerCommandHandler> logger = null)
 {
     _connectionAccessor = connectionAccessor;
     _logger             = logger;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DataConnectionServerCommandHandler"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The FTP connection accessor.</param>
 /// <param name="logger">The logger.</param>
 public DataConnectionServerCommandHandler(
     IFtpConnectionAccessor connectionAccessor,
     ILogger <DataConnectionServerCommandHandler>?logger = null)
 {
     _connectionAccessor = connectionAccessor;
     _logger             = logger;
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AppeCommandHandler"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The accessor to get the connection that is active during the <see cref="Process"/> method execution.</param>
 /// <param name="backgroundTransferWorker">The background transfer worker service.</param>
 public AppeCommandHandler(
     [NotNull] IFtpConnectionAccessor connectionAccessor,
     [NotNull] IBackgroundTransferWorker backgroundTransferWorker)
     : base(connectionAccessor, "APPE")
 {
     _backgroundTransferWorker = backgroundTransferWorker;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SendResponseServerCommandHandler"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The FTP connection accessor.</param>
 /// <param name="logger">The logger.</param>
 public SendResponseServerCommandHandler(
     IFtpConnectionAccessor connectionAccessor,
     ILogger <SendResponseServerCommandHandler>?logger = null)
 {
     _connectionAccessor = connectionAccessor;
     _logger             = logger;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ActiveDataConnectionFeatureFactory"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The FTP connection accessor.</param>
 /// <param name="validators">An enumeration of FTP connection validators.</param>
 public ActiveDataConnectionFeatureFactory(
     IFtpConnectionAccessor connectionAccessor,
     IEnumerable <IFtpDataConnectionValidator> validators)
 {
     _connectionAccessor = connectionAccessor;
     _validators         = validators.ToList();
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SecureDataConnectionWrapper"/> class.
 /// </summary>
 /// <param name="connectionAccessor">Accessor for the FTP connection.</param>
 /// <param name="sslStreamWrapperFactory">The SSL stream wrapper factory.</param>
 public SecureDataConnectionWrapper(
     [NotNull] IFtpConnectionAccessor connectionAccessor,
     [NotNull] ISslStreamWrapperFactory sslStreamWrapperFactory)
 {
     _connectionAccessor      = connectionAccessor;
     _sslStreamWrapperFactory = sslStreamWrapperFactory;
 }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SendResponseServerCommandHandler"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The FTP connection accessor.</param>
 /// <param name="logger">The logger.</param>
 public SendResponseServerCommandHandler(
     [NotNull] IFtpConnectionAccessor connectionAccessor,
     [CanBeNull] ILogger <SendResponseServerCommandHandler> logger = null)
 {
     _connectionAccessor = connectionAccessor;
     _logger             = logger;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FillConnectionFileSystemDataAction"/> class.
 /// </summary>
 /// <param name="ftpConnectionAccessor">The FTP connection accessor.</param>
 /// <param name="fileSystemFactory">The file system factory.</param>
 public FillConnectionFileSystemDataAction(
     [NotNull] IFtpConnectionAccessor ftpConnectionAccessor,
     [NotNull] IFileSystemClassFactory fileSystemFactory)
 {
     _ftpConnectionAccessor = ftpConnectionAccessor;
     _fileSystemFactory     = fileSystemFactory;
 }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StatCommandHandler"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The accessor to get the connection that is active during the <see cref="Process"/> method execution.</param>
 /// <param name="server">The FTP server.</param>
 /// <param name="backgroundTransferWorker">The background transfer worker service.</param>
 public StatCommandHandler(
     [NotNull] IFtpConnectionAccessor connectionAccessor,
     [NotNull] IFtpServer server,
     [NotNull] IBackgroundTransferWorker backgroundTransferWorker)
     : base(connectionAccessor, "STAT")
 {
     _server = server;
     _backgroundTransferWorker = backgroundTransferWorker;
 }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PamMembershipProvider"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The FTP connection accessor.</param>
 /// <param name="pamService">The PAM service.</param>
 /// <param name="options">The options for this membership provider.</param>
 public PamMembershipProvider(
     [NotNull] IFtpConnectionAccessor connectionAccessor,
     [NotNull] IPamService pamService,
     [NotNull] IOptions <PamMembershipProviderOptions> options)
 {
     _connectionAccessor = connectionAccessor;
     _pamService         = pamService;
     _options            = options.Value;
 }
Пример #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PassCommandHandler"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The accessor to get the connection that is active during the <see cref="Process"/> method execution.</param>
 /// <param name="membershipProviders">The membership providers.</param>
 /// <param name="fileSystemClassFactory">The file system access factory.</param>
 public PassCommandHandler(
     [NotNull] IFtpConnectionAccessor connectionAccessor,
     [NotNull] IEnumerable <IMembershipProvider> membershipProviders,
     [NotNull] IFileSystemClassFactory fileSystemClassFactory)
     : base(connectionAccessor, "PASS")
 {
     _membershipProviders    = membershipProviders;
     _fileSystemClassFactory = fileSystemClassFactory;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TlsEnableServerCommandHandler"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The FTP connection accessor.</param>
 /// <param name="options">Options for the AUTH TLS command.</param>
 /// <param name="logger">The logger.</param>
 public TlsEnableServerCommandHandler(
     IFtpConnectionAccessor connectionAccessor,
     IOptions <AuthTlsOptions> options,
     ILogger <TlsEnableServerCommandHandler>?logger = null)
 {
     _connectionAccessor = connectionAccessor;
     _logger             = logger;
     _serverCertificate  = options.Value.ServerCertificate;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SiteBlstCommandExtension"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The accessor to get the connection that is active during the <see cref="Process"/> method execution.</param>
 /// <param name="backgroundTransferWorker">The background transfer worker service.</param>
 /// <param name="logger">The logger.</param>
 public SiteBlstCommandExtension(
     [NotNull] IFtpConnectionAccessor connectionAccessor,
     [NotNull] IBackgroundTransferWorker backgroundTransferWorker,
     [CanBeNull] ILogger <SiteBlstCommandExtension> logger = null)
     : base(connectionAccessor, "SITE", "BLST")
 {
     _backgroundTransferWorker = backgroundTransferWorker;
     _logger = logger;
 }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SiteCommandHandler"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The accessor to get the connection that is active during the <see cref="Process"/> method execution.</param>
 /// <param name="extensions">All registered extensions.</param>
 public SiteCommandHandler(
     IFtpConnectionAccessor connectionAccessor,
     [NotNull, ItemNotNull] IEnumerable <IFtpCommandHandlerExtension> extensions)
     : base(connectionAccessor, "SITE")
 {
     Extensions = extensions
                  .Where(x => Names.Any(name => string.Equals(name, x.ExtensionFor, StringComparison.OrdinalIgnoreCase)))
                  .SelectMany(x => x.Names.Select(n => new { Name = n, Extension = x }))
                  .ToDictionary(x => x.Name, x => x.Extension, StringComparer.OrdinalIgnoreCase);
 }
Пример #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PassiveDataConnectionFeatureFactory"/> class.
 /// </summary>
 /// <param name="pasvListenerFactory">The PASV listener factory.</param>
 /// <param name="connectionAccessor">The FTP connection accessor.</param>
 /// <param name="validators">An enumeration of FTP connection validators.</param>
 /// <param name="logger">The logger.</param>
 public PassiveDataConnectionFeatureFactory(
     IPasvListenerFactory pasvListenerFactory,
     IFtpConnectionAccessor connectionAccessor,
     IEnumerable <IFtpDataConnectionValidator> validators,
     ILogger <PassiveDataConnectionFeatureFactory>?logger = null)
 {
     _pasvListenerFactory = pasvListenerFactory;
     _connectionAccessor  = connectionAccessor;
     _logger     = logger;
     _validators = validators.ToList();
 }
Пример #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SetHomeDirectoryAction"/> class.
 /// </summary>
 /// <param name="options">The options for the <see cref="SetHomeDirectoryAction"/>.</param>
 /// <param name="ftpConnectionAccessor">The FTP connection accessor.</param>
 /// <param name="accountDirectoryQuery">Interface to query account directories.</param>
 /// <param name="logger">The logger.</param>
 public SetHomeDirectoryAction(
     [NotNull] IOptions <SetHomeDirectoryActionOptions> options,
     [NotNull] IFtpConnectionAccessor ftpConnectionAccessor,
     [NotNull] IAccountDirectoryQuery accountDirectoryQuery,
     [CanBeNull] ILogger <SetHomeDirectoryAction> logger = null)
 {
     _ftpConnectionAccessor = ftpConnectionAccessor;
     _accountDirectoryQuery = accountDirectoryQuery;
     _logger = logger;
     _createMissingDirectories = options.Value.CreateMissingDirectories;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SetHomeDirectoryAction"/> class.
 /// </summary>
 /// <param name="options">The options for the <see cref="SetHomeDirectoryAction"/>.</param>
 /// <param name="ftpConnectionAccessor">The FTP connection accessor.</param>
 /// <param name="accountDirectoryQuery">Interface to query account directories.</param>
 /// <param name="logger">The logger.</param>
 public SetHomeDirectoryAction(
     IOptions <SetHomeDirectoryActionOptions> options,
     IFtpConnectionAccessor ftpConnectionAccessor,
     IAccountDirectoryQuery accountDirectoryQuery,
     ILogger <SetHomeDirectoryAction>?logger = null)
 {
     _ftpConnectionAccessor = ftpConnectionAccessor;
     _accountDirectoryQuery = accountDirectoryQuery;
     _logger = logger;
     _createMissingDirectories = options.Value.CreateMissingDirectories;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PassiveDataConnectionFeatureFactory"/> class.
 /// </summary>
 /// <param name="pasvListenerFactory">The PASV listener factory.</param>
 /// <param name="connectionAccessor">The FTP connection accessor.</param>
 /// <param name="validators">An enumeration of FTP connection validators.</param>
 /// <param name="logger">The logger.</param>
 public PassiveDataConnectionFeatureFactory(
     [NotNull] IPasvListenerFactory pasvListenerFactory,
     [NotNull] IFtpConnectionAccessor connectionAccessor,
     [NotNull][ItemNotNull] IEnumerable <IFtpDataConnectionValidator> validators,
     [CanBeNull] ILogger <PassiveDataConnectionFeatureFactory> logger = null)
 {
     _pasvListenerFactory = pasvListenerFactory;
     _connectionAccessor  = connectionAccessor;
     _logger     = logger;
     _validators = validators.ToList();
 }
Пример #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FtpCommandHandler"/> class.
        /// </summary>
        /// <param name="connectionAccessor">The accessor to get the connection that is active during the <see cref="Process"/> method execution.</param>
        /// <param name="name">The command name.</param>
        /// <param name="alternativeNames">Alternative names.</param>
        protected FtpCommandHandler([NotNull] IFtpConnectionAccessor connectionAccessor, [NotNull] string name, [NotNull, ItemNotNull] params string[] alternativeNames)
        {
            _connectionAccessor = connectionAccessor;
            var names = new List <string>
            {
                name,
            };

            names.AddRange(alternativeNames);
            Names = names;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FtpConnectionIdleCheck"/> class.
        /// </summary>
        /// <param name="connectionAccessor">The FTP connection accessor.</param>
        /// <param name="options">FTP connection options.</param>
        public FtpConnectionIdleCheck(
            IFtpConnectionAccessor connectionAccessor,
            IOptions <FtpConnectionOptions> options)
        {
            var connection = connectionAccessor.FtpConnection;

            _inactivityTimeout = options.Value.InactivityTimeout ?? TimeSpan.MaxValue;
            UpdateLastActiveTime();

            if (connection is IObservable <IFtpConnectionEvent> observable)
            {
                _subscription = observable.Subscribe(new EventObserver(this));
            }
            else
            {
                _subscription = null;
            }
        }
Пример #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FtpConnection"/> class.
        /// </summary>
        /// <param name="socket">The socket to use to communicate with the client.</param>
        /// <param name="connectionAccessor">The accessor to get the connection that is active during the <see cref="FtpCommandHandler.Process"/> method execution.</param>
        /// <param name="commandHandlerExtensions">The registered command handler extensions.</param>
        /// <param name="logger">The logger for the FTP connection.</param>
        /// <param name="options">The options for the FTP connection.</param>
        /// <param name="commandHandlers">The registered command handlers.</param>
        public FtpConnection(
            [NotNull] TcpClient socket,
            [NotNull] IOptions <FtpConnectionOptions> options,
            [NotNull] IFtpConnectionAccessor connectionAccessor,
            [NotNull, ItemNotNull] IEnumerable <IFtpCommandHandler> commandHandlers,
            [NotNull, ItemNotNull] IEnumerable <IFtpCommandHandlerExtension> commandHandlerExtensions,
            [CanBeNull] ILogger <IFtpConnection> logger = null)
        {
            var endpoint = (IPEndPoint)socket.Client.RemoteEndPoint;

            RemoteAddress = new Address(endpoint.Address.ToString(), endpoint.Port);

            var properties = new Dictionary <string, object>
            {
                ["RemoteAddress"] = RemoteAddress.ToString(true),
                ["RemoteIp"]      = RemoteAddress.IPAddress?.ToString(),
                ["RemotePort"]    = RemoteAddress.Port,
            };

            _loggerScope = logger?.BeginScope(properties);

            _socket             = socket;
            _connectionAccessor = connectionAccessor;
            Log             = logger;
            SocketStream    = OriginalStream = socket.GetStream();
            Encoding        = options.Value.DefaultEncoding ?? Encoding.ASCII;
            PromiscuousPasv = options.Value.PromiscuousPasv;
            Data            = new FtpConnectionData(new BackgroundCommandHandler(this));

            var commandHandlersList = commandHandlers.ToList();
            var dict = commandHandlersList
                       .SelectMany(x => x.Names, (item, name) => new { Name = name, Item = item })
                       .ToLookup(x => x.Name, x => x.Item, StringComparer.OrdinalIgnoreCase)
                       .ToDictionary(x => x.Key, x => x.Last());

            _extensions = commandHandlerExtensions.ToList();

            CommandHandlers = dict;
        }
Пример #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MfctCommandHandler"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The accessor to get the connection that is active during the <see cref="Process"/> method execution.</param>
 public MfctCommandHandler(IFtpConnectionAccessor connectionAccessor)
     : base(connectionAccessor, "MFCT")
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="OptsMlstCommandExtension"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The accessor to get the connection that is active during the <see cref="Process"/> method execution.</param>
 public OptsMlstCommandExtension([NotNull] IFtpConnectionAccessor connectionAccessor)
     : base(connectionAccessor, "OPTS", "MLST")
 {
 }
Пример #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CdUpCommandHandler"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The accessor to get the connection that is active during the <see cref="Process"/> method execution.</param>
 public CdUpCommandHandler(IFtpConnectionAccessor connectionAccessor)
     : base(connectionAccessor, "CDUP", "XCUP")
 {
 }
Пример #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RntoCommandHandler"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The accessor to get the connection that is active during the <see cref="Process"/> method execution.</param>
 public RntoCommandHandler(IFtpConnectionAccessor connectionAccessor)
     : base(connectionAccessor, "RNTO")
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PamSessionAuthorizationAction"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The FTP connection accessor.</param>
 public PamSessionAuthorizationAction(IFtpConnectionAccessor connectionAccessor)
 {
     _connectionAccessor = connectionAccessor;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ReflectionServerCommandExecutor"/> class.
 /// </summary>
 /// <param name="ftpConnectionAccessor">Accessor to get the FTP connection.</param>
 public ReflectionServerCommandExecutor([NotNull] IFtpConnectionAccessor ftpConnectionAccessor)
 {
     _ftpConnectionAccessor = ftpConnectionAccessor;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FillConnectionAccountDataAction"/> class.
 /// </summary>
 /// <param name="ftpConnectionAccessor">The FTP connection accessor.</param>
 public FillConnectionAccountDataAction(
     IFtpConnectionAccessor ftpConnectionAccessor)
 {
     _ftpConnectionAccessor = ftpConnectionAccessor;
 }
Пример #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FeatCommandHandler"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The accessor to get the connection that is active during the <see cref="Process"/> method execution.</param>
 public FeatCommandHandler(IFtpConnectionAccessor connectionAccessor)
     : base(connectionAccessor, "FEAT")
 {
 }
Пример #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CloseConnectionServerCommandHandler"/> class.
 /// </summary>
 /// <param name="connectionAccessor">The FTP connection accessor.</param>
 public CloseConnectionServerCommandHandler(
     IFtpConnectionAccessor connectionAccessor)
 {
     _connectionAccessor = connectionAccessor;
 }