Files
DearFTP/DearFTP/Connection/Commands/CommandsDispatcher.cs
Eveldee 94431aebb8 Clean code
Remove unused usings
Remove blank lines
Fix style issues
2019-07-20 16:16:23 +02:00

65 lines
2.0 KiB
C#

using System;
using System.Linq;
namespace DearFTP.Connection.Commands
{
class CommandsDispatcher
{
public ICommand[] Commands { get; } = new ICommand[]
{
new AuthCommand(),
new ClntCommand(),
new CwdCommand(),
new DeleteCommand(),
new HelpCommand(),
new FeaturesCommand(),
new FileModificationTimeCommand(),
new ListCommand(),
new ListMachineCommand(),
new MakeDirectoryCommand(),
new OptionsCommand(),
new ParentDirectoryCommand(),
new PassiveCommand(),
new ProtectionBufferSizeCommand(),
new ProtectionCommand(),
new PwdCommand(),
new QuitCommand(),
new RenameCommand(),
new RetrieveCommand(),
new RestartCommand(),
new SiteCommand(),
new SizeCommand(),
new StoreCommand(),
new SystemCommand(),
new TypeCommand(),
new UserCommand()
};
public void Dispatch(Session session, string command, string argument)
{
if (command == "END")
{
session.Stop();
return;
}
var commandExecutor = Commands.FirstOrDefault(x => x.Aliases.Contains(command, StringComparer.OrdinalIgnoreCase));
var stream = session.FtpStream;
if (commandExecutor == null)
{
stream.Send(ResponseCode.NotImplemented, $"Command '{command}' not implemented or invalid");
return;
}
if (session.Configuration.Tls.ForceTls && !session.IsTlsProtected && command.ToUpper() != "AUTH")
{
stream.Send(ResponseCode.InsufficientProtection, "Not protected connection is not allowed on this server.");
return;
}
commandExecutor.Execute(session, stream, command, argument);
}
}
}