Add implicit FTPS
This commit is contained in:
@@ -66,6 +66,12 @@ namespace DearFTP.Configurations
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Server.ImplicitFtpsPort != 0 && !Tls.AllowTls)
|
||||
{
|
||||
Console.WriteLine("Implicit FTPS is activated but TLS is not allowed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Tls.AllowTls)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Tls.CertificatePath))
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace DearFTP.Configurations
|
||||
{
|
||||
public ushort Port { get; set; } = 21;
|
||||
public ushort ForceDataPort { get; set; } = 0;
|
||||
public ushort ImplicitFtpsPort { get; set; } = 0;
|
||||
public string MOTD { get; set; } = "DearFTP v0.1";
|
||||
public string LoginMessage { get; set; } = "Logged in as %user%";
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace DearFTP
|
||||
|
||||
private bool _isRunning = true;
|
||||
private TcpListener _listener;
|
||||
private TcpListener _ftpsListener;
|
||||
|
||||
public FtpServer()
|
||||
{
|
||||
@@ -39,13 +40,22 @@ namespace DearFTP
|
||||
Logger.Log("DearFTP started");
|
||||
Logger.Log();
|
||||
|
||||
int implicitFtpsPort = Configuration.Server.ImplicitFtpsPort;
|
||||
|
||||
if (implicitFtpsPort != 0)
|
||||
{
|
||||
Task.Run(() => FtpsTcpLoop());
|
||||
}
|
||||
|
||||
TcpLoop();
|
||||
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_isRunning = false;
|
||||
_listener.Stop();
|
||||
_ftpsListener?.Stop();
|
||||
StaticDataConnection.Stop();
|
||||
}
|
||||
|
||||
@@ -64,12 +74,33 @@ namespace DearFTP
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateSession(TcpClient client)
|
||||
private void FtpsTcpLoop()
|
||||
{
|
||||
_ftpsListener = new TcpListener(IPAddress.Any, Configuration.Server.ImplicitFtpsPort);
|
||||
_ftpsListener.Start(5);
|
||||
|
||||
Logger.Log($"Listening on: {_ftpsListener.LocalEndpoint}");
|
||||
|
||||
while (_isRunning)
|
||||
{
|
||||
var client = _ftpsListener.AcceptTcpClient();
|
||||
|
||||
Task.Run(() => CreateSession(client, true));
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateSession(TcpClient client, bool implicitFtps = false)
|
||||
{
|
||||
Logger.Log($"Client connected: {client.Client.RemoteEndPoint}");
|
||||
|
||||
using (var session = new Session(client))
|
||||
{
|
||||
if (implicitFtps)
|
||||
{
|
||||
session.ActivateTls();
|
||||
session.DataConnection.ActivateTls();
|
||||
}
|
||||
|
||||
session.Start();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user