Initial commit.
This commit is contained in:
55
DearFTP/Connection/Commands/CommandsDispatcher.cs
Normal file
55
DearFTP/Connection/Commands/CommandsDispatcher.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
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 ParentDirectoryCommand(),
|
||||
new PassiveCommand(),
|
||||
new PwdCommand(),
|
||||
new QuitCommand(),
|
||||
new RenameCommand(),
|
||||
new RetrieveCommand(),
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user