Esempio n. 1
0
 public static void BufferNotDetached(IArrayBufferView buffer)
 {
     Guard.ArgumentNotNull(buffer, "buffer");
     if (buffer.Buffer.IsDetached)
     {
         throw new EcmaTypeErrorException(InternalString.Error.BufferDetached);
     }
 }
        /// <summary>
        /// Verifies user authentication status and performs all necessary actions for the command.
        /// </summary>
        /// <param name="arguments">Command arguments</param>
        /// <param name="session">FTP session context</param>
        /// <param name="cancellation">Cancellation token</param>
        /// <returns>A <see cref="Task"/> that represents an asynchronous operation.</returns>
        public override async Task Handle(IArrayBufferView arguments, FtpSessionState session, CancellationToken cancellation)
        {
            if (session.FileSystem == null)
            {
                await session.ControlChannel.Send(FtpResponses.NotLoggedIn, cancellation);

                return;
            }

            await base.Handle(arguments, session, cancellation);
        }
Esempio n. 3
0
        /// <summary>
        /// Processes the command and writes the response in the control channel.
        /// </summary>
        /// <param name="command">Command name</param>
        /// <param name="arguments">Command arguments</param>
        /// <param name="cancellation">Cancellation token</param>
        /// <returns>A <see cref="Task"/> that represents an asynchronous operation.</returns>
        protected override async Task OnCommand(string command, IArrayBufferView arguments, CancellationToken cancellation)
        {
            IFtpCommand commandHandler;

            if (supportedCommands.TryGetValue(command, out commandHandler))
            {
                try
                {
                    await commandHandler.Handle(arguments, session, cancellation);
                }
                catch (Exception error)
                {
                    session.Logger.WriteError(error.Message);
                    await Send(FtpResponses.InternalError, cancellation);
                }
            }
            else
            {
                session.Logger.WriteWarning(TraceResources.CommandNotSupported);
                await Send(FtpResponses.NotImplemented, cancellation);
            }
        }
 /// <summary>
 /// Converts command arguments from binary form to string using current paths encoding.
 /// </summary>
 /// <param name="arguments">Arguments in binary form</param>
 /// <param name="session">FTP session context</param>
 /// <returns>Command arguments as string.</returns>
 protected override string ReadArguments(IArrayBufferView arguments, FtpSessionState session)
 {
     return(arguments.ToString(session.PathEncoding));
 }
Esempio n. 5
0
 /// <summary>
 /// Converts command arguments from binary form to string using current control channel encoding.
 /// </summary>
 /// <param name="arguments">Arguments in binary form</param>
 /// <param name="session">FTP session context</param>
 /// <returns>Command arguments as string.</returns>
 protected virtual string ReadArguments(IArrayBufferView arguments, FtpSessionState session)
 {
     return(arguments.ToString(session.ControlEncoding));
 }
Esempio n. 6
0
 /// <summary>
 /// Cleans up volatile session state and performs all necessary actions for the command.
 /// </summary>
 /// <param name="arguments">Command arguments</param>
 /// <param name="session">FTP session context</param>
 /// <param name="cancellation">Cancellation token</param>
 /// <returns>A <see cref="Task"/> that represents an asynchronous operation.</returns>
 public virtual async Task Handle(IArrayBufferView arguments, FtpSessionState session, CancellationToken cancellation)
 {
     CleanupRenameSource(session);
     CleanupTransferRestartOffset(session);
     await HandleCommand(ReadArguments(arguments, session), session, cancellation);
 }
 /// <summary>
 /// Processes the command received from the client.
 /// </summary>
 /// <param name="command">Command name</param>
 /// <param name="arguments">Command arguments</param>
 /// <param name="cancellation">Cancellation token</param>
 /// <returns>A <see cref="Task"/> that represents an asynchronous operation.</returns>
 protected abstract Task OnCommand(string command, IArrayBufferView arguments, CancellationToken cancellation);