FubarDevelopment / FtpServer

Portable FTP server written in .NET
http://fubardevelopment.github.io/FtpServer/
MIT License
482 stars 163 forks source link

Deny new Connections but not drop existing #42

Closed wasabii closed 5 years ago

wasabii commented 6 years ago

Is there a way to deny new connections to the server (stop the listener) without stopping existing connections? I would like to implement the ability to wait for connections to exit before Stop is processed.

fubar-coder commented 6 years ago

You mean something like a pause/resume? No, it's not implemented, but a pull request is welcome 😊.

fubar-coder commented 5 years ago

Will be fixed in 3.0.0-rc.4 or 3.0.0 (whatever comes first).

I'm not really happy with the API, but I cannot think of a better one:

// Get the FTP server
var ftpServer = serviceProvider.GetRequiredService<IFtpServer>();

// Cast to ICommunicationService and pause the server (accepting connections)
await ((ICommunicationService)ftpServer).PauseAsync(CancellationToken.None);

// Cast to ICommunicationService and continue the server (accepting connections)
await ((ICommunicationService)ftpServer).ContinueAsync(CancellationToken.None);