Files
DearFTP/DearFTP/Connection/Commands/CommandsDispatcher.cs
2019-07-18 14:22:11 +02:00

58 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DearFTP.Connection.Commands
{
class CommandsDispatcher
{
public ICommand[] Commands { get; } = new ICommand[]
{
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 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));
if (commandExecutor == null)
{
session.FtpStream.Send(ResponseCode.NotImplemented, $"Command '{command}' not implemented or invalid");
return;
}
commandExecutor.Execute(session, session.FtpStream, command, argument);
}
}
}