コード例 #1
0
        private Task <IFtpResponse> SendBlstDirectly()
        {
            var taskStates = _backgroundTransferWorker.GetStates();

            if (taskStates.Count == 0)
            {
                return(Task.FromResult <IFtpResponse>(new FtpResponse(211, T("No background tasks"))));
            }

            return(Task.FromResult <IFtpResponse>(
                       new FtpResponseList(
                           211,
                           T("Active background tasks:"),
                           T("END"),
                           GetLines(taskStates))));
        }
コード例 #2
0
        private async Task <FtpResponse> SendBlstDirectly(CancellationToken cancellationToken)
        {
            var taskStates = _backgroundTransferWorker.GetStates();

            if (taskStates.Count == 0)
            {
                return(new FtpResponse(211, "No background tasks"));
            }

            await Connection.WriteAsync("211-Active background tasks:", cancellationToken).ConfigureAwait(false);

            foreach (var line in GetLines(taskStates))
            {
                await Connection.WriteAsync($" {line}", cancellationToken).ConfigureAwait(false);
            }

            return(new FtpResponse(211, "END"));
        }
コード例 #3
0
        /// <inheritdoc/>
        public override async Task <IFtpResponse> Process(FtpCommand command, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(command.Argument))
            {
                var taskStates    = _backgroundTransferWorker.GetStates();
                var statusMessage = new StringBuilder();
                statusMessage.AppendFormat(
                    "Server functional, {0} open connections",
                    _server.Statistics.ActiveConnections);
                if (taskStates.Count != 0)
                {
                    statusMessage.AppendFormat(", {0} active background transfers", taskStates.Count);
                }

                return(new FtpResponse(211, statusMessage.ToString()));
            }

            var mask = command.Argument;

            if (!mask.EndsWith("*"))
            {
                mask += "*";
            }

            var fsFeature = Connection.Features.Get <IFileSystemFeature>();

            var globOptions = new GlobOptions();

            globOptions.Evaluation.CaseInsensitive = fsFeature.FileSystem.FileSystemEntryComparer.Equals("a", "A");

            var glob = Glob.Parse(mask, globOptions);

            var formatter = new LongListFormatter();

            var entries = await fsFeature.FileSystem.GetEntriesAsync(fsFeature.CurrentDirectory, cancellationToken)
                          .ConfigureAwait(false);

            var lines = entries.Where(x => glob.IsMatch(x.Name))
                        .Select(x => formatter.Format(x, x.Name))
                        .ToList();

            return(new FtpResponseList(
                       211,
                       $"STAT {command.Argument}",
                       "STAT",
                       lines));
        }
コード例 #4
0
        /// <inheritdoc/>
        public override async Task <FtpResponse> Process(FtpCommand command, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(command.Argument))
            {
                var taskStates    = _backgroundTransferWorker.GetStates();
                var statusMessage = new StringBuilder();
                statusMessage.AppendFormat("Server functional, {0} open connections", _server.Statistics.ActiveConnections);
                if (taskStates.Count != 0)
                {
                    statusMessage.AppendFormat(", {0} active background transfers", taskStates.Count);
                }

                return(new FtpResponse(211, statusMessage.ToString()));
            }

            var mask = command.Argument;

            if (!mask.EndsWith("*"))
            {
                mask += "*";
            }

            var globOptions = new GlobOptions();

            globOptions.Evaluation.CaseInsensitive = Data.FileSystem.FileSystemEntryComparer.Equals("a", "A");

            var glob = Glob.Parse(mask, globOptions);

            var formatter = new LongListFormatter();
            await Connection.WriteAsync($"211-STAT {command.Argument}", cancellationToken).ConfigureAwait(false);

            var entries = await Data.FileSystem.GetEntriesAsync(Data.CurrentDirectory, cancellationToken)
                          .ConfigureAwait(false);

            foreach (var entry in entries.Where(x => glob.IsMatch(x.Name)))
            {
                var line = formatter.Format(entry, entry.Name);
                Connection.Log?.LogDebug(line);
                await Connection.WriteAsync($" {line}", cancellationToken).ConfigureAwait(false);
            }

            return(new FtpResponse(211, "STAT"));
        }
コード例 #5
0
        /// <inheritdoc />
        public IEnumerable <(string label, string value)> GetInfo()
        {
            var states = _backgroundTransferWorker.GetStates();

            yield return("Background uploads", $"{states.Count}");
        }