FubarDevelopment / FtpServer

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

Error "The TLS connection was non-properly terminated" #135

Open ishimmings opened 2 years ago

ishimmings commented 2 years ago

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.

fubar-coder commented 2 years ago

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.

sergshu commented 1 year ago

I have created a .NET 6.0 project but the error still occurs