Пример #1
0
        private async Task CommandStorAsync(string parameter)
        {
            if (!authenticated)
            {
                await ReplyAsync(FtpReplyCode.NotLoggedIn, "You need to log in first");

                return;
            }
            if (string.IsNullOrEmpty(parameter))
            {
                await ReplyAsync(
                    FtpReplyCode.SyntaxErrorInParametersOrArguments,
                    "Syntax error, path is missing");

                return;
            }
            if (transmissionMode != TransmissionMode.Stream)
            {
                await ReplyAsync(FtpReplyCode.NotImplemented, "Only supports stream mode");

                return;
            }

            try
            {
                using (Stream fileStream = await fileProvider.CreateFileForWriteAsync(parameter))
                {
                    await OpenDataConnectionAsync();

                    await dataConnection.RecieveAsync(fileStream);

                    await fileStream.FlushAsync();
                }
            }
            catch (FileBusyException ex)
            {
                await ReplyAsync(FtpReplyCode.FileBusy, string.Format("Temporarily unavailable: {0}", ex.Message));

                return;
            }
            catch (FileSpaceInsufficientException ex)
            {
                await ReplyAsync(FtpReplyCode.FileSpaceInsufficient, string.Format("Writing file denied: {0}", ex.Message));

                return;
            }

            await dataConnection.DisconnectAsync();

            await ReplyAsync(FtpReplyCode.SuccessClosingDataConnection, "File has been recieved");

            return;
        }