private Task ExecuteBackgroundCommandAsync( FtpContext context, IFtpCommandBase handler, CancellationToken cancellationToken) { var backgroundTaskFeature = _connection.Features.Get <IBackgroundTaskLifetimeFeature?>(); if (backgroundTaskFeature == null) { backgroundTaskFeature = new BackgroundTaskLifetimeFeature( handler, context.Command, ct => { var executionContext = new FtpExecutionContext(context, handler, ct); return(_executionDelegate(executionContext)); }, cancellationToken); _connection.Features.Set(backgroundTaskFeature); return(Task.CompletedTask); } return(SendResponseAsync( new FtpResponse(503, T("Parallel commands aren't allowed.")), cancellationToken)); }
public Client(FtpContext ftpContext, IConfiguration configuration, IHostingEnvironment environment) { _ftpContext = ftpContext; _port = int.Parse(configuration["Port"]); _host = configuration["Host"]; _enviroment = environment; }
/// <summary> /// Initializes a new instance of the <see cref="FtpExecutionContext"/> class. /// </summary> /// <param name="ftpContext">The FTP context.</param> /// <param name="commandHandler">The FTP command handler.</param> /// <param name="commandAborted">The cancellation token signalling an aborted command.</param> public FtpExecutionContext( [NotNull] FtpContext ftpContext, [NotNull] IFtpCommandBase commandHandler, CancellationToken commandAborted) : base(ftpContext.Command, ftpContext.ServerCommandWriter, ftpContext.Connection) { CommandHandler = commandHandler; CommandAborted = commandAborted; }
/// <inheritdoc /> public async Task DispatchAsync(FtpContext context, CancellationToken cancellationToken) { var loginStateMachine = _loginStateMachine ?? throw new InvalidOperationException("Login state machine not initialized."); var commandHandlerContext = new FtpCommandHandlerContext(context); var result = _commandActivator.Create(commandHandlerContext); if (result == null) { await SendResponseAsync( new FtpResponse(500, T("Syntax error, command unrecognized.")), cancellationToken) .ConfigureAwait(false); return; } var handler = result.Handler; var isLoginRequired = result.Information.IsLoginRequired; if (isLoginRequired && loginStateMachine.Status != SecurityStatus.Authorized) { await SendResponseAsync( new FtpResponse(530, T("Not logged in.")), cancellationToken) .ConfigureAwait(false); return; } if (result.Information.IsAbortable) { await ExecuteBackgroundCommandAsync(context, handler, cancellationToken) .ConfigureAwait(false); } else { var executionContext = new FtpExecutionContext(context, handler, cancellationToken); await _executionDelegate(executionContext) .ConfigureAwait(false); } }
/// <summary> /// Initializes a new instance of the <see cref="FtpCommandHandlerContext"/> class. /// </summary> /// <param name="ftpContext">The FTP context.</param> public FtpCommandHandlerContext(FtpContext ftpContext) { FtpContext = ftpContext; }