FtpServer
FtpServer copied to clipboard
Error "The TLS connection was non-properly terminated"
I am using Windows 11. I have confirmed the certificate is correct by installing it and using it in a FTP site configured in IIS on my machine (disabled before running this).
With the following configuration:
var services = new ServiceCollection();
services.Configure<DotNetFileSystemOptions>(opt => opt.RootPath = @"C:\FTP");
services.AddFtpServer(builder => builder
.UseDotNetFileSystem()
.UseImplicitTls(new X509Certificate2(@"C:\localhost.pfx", "password"))
.EnableAnonymousAuthentication());
services.Configure<FtpServerOptions>(opt =>
{
opt.ServerAddress = "localhost";
opt.Port = 990;
});
var serviceProvider = services.BuildServiceProvider();
var ftpServerHost = serviceProvider.GetRequiredService<IFtpServerHost>();
await ftpServerHost.StartAsync(CancellationToken.None).ConfigureAwait(false);
I get the following output using FileZilla:
Status: Resolving address of localhost
Status: Connecting to [::1]:990...
Status: Connection established, initializing TLS...
Status: TLS connection established, waiting for welcome message...
Error: GnuTLS error -110 in gnutls_record_recv: The TLS connection was non-properly terminated.
Status: Server did not properly shut down TLS connection
Error: Could not read from socket: ECONNABORTED - Connection aborted
Error: Could not connect to server
When trying to access in code using FluentFtp I get the error The connection was terminated before a greeting could be read. while connecting in the HandshakeAsync method with the following log output:
# ConnectAsync()
Status: Connecting to ::1:990
Status: FTPS Authentication Successful
Status: Time to activate encryption: 0h 0m 0s. Total Seconds: 0.0377264.
Any help greatly appreciated, thank you.
This is a (sadly) well-known GnuTLS bug, which interprets a "should" in the specification as a "must". The solution is to upgrade to .NET 6.0, which works better together with GnuTLS.
I have created a .NET 6.0 project but the error still occurs