Add SSL/TLS protocol support

This commit is contained in:
2019-07-20 12:52:41 +02:00
parent c78181a1de
commit 23dfbe8788
15 changed files with 1331 additions and 37 deletions

View File

@@ -9,6 +9,7 @@ namespace DearFTP.Connection.Commands
{
public ICommand[] Commands { get; } = new ICommand[]
{
new AuthCommand(),
new ClntCommand(),
new CwdCommand(),
new DeleteCommand(),
@@ -21,6 +22,8 @@ namespace DearFTP.Connection.Commands
new OptionsCommand(),
new ParentDirectoryCommand(),
new PassiveCommand(),
new ProtectionBufferSizeCommand(),
new ProtectionCommand(),
new PwdCommand(),
new QuitCommand(),
new RenameCommand(),
@@ -43,15 +46,21 @@ namespace DearFTP.Connection.Commands
}
var commandExecutor = Commands.FirstOrDefault(x => x.Aliases.Contains(command, StringComparer.OrdinalIgnoreCase));
var stream = session.FtpStream;
if (commandExecutor == null)
{
session.FtpStream.Send(ResponseCode.NotImplemented, $"Command '{command}' not implemented or invalid");
stream.Send(ResponseCode.NotImplemented, $"Command '{command}' not implemented or invalid");
return;
}
commandExecutor.Execute(session, session.FtpStream, command, argument);
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);
}
}
}