FubarDevelopment / FtpServer

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

Cant stop the Server #143

Open Crashdummyy opened 1 year ago

Crashdummyy commented 1 year ago

Hi there

I use this server in an asp.net core webai where I just start it when I need to obtain a specific directory.

    public Task StartServerForBasedir(string baseDir,
                                      CancellationToken cancellationToken = default)
    {
        var ioc = new ServiceCollection();

        ioc.Configure<DotNetFileSystemOptions>(options => options.RootPath = baseDir);

        ioc.AddFtpServer(server => server.UseDotNetFileSystem().UseSingleRoot())
           .AddSingleton<IMembershipProvider, BuddyFtpProvider>();

        ioc.Configure<FtpServerOptions>(options => options.Port = ClassKey.Ports.FTP);

        serviceProvider = ioc.BuildServiceProvider();

        ftpService = serviceProvider.GetRequiredService<IFtpServerHost>();
        return ftpService.StartAsync(cancellationToken);
    }

    public async Task StopServer(CancellationToken cancellationToken = default)
    {
        if (ftpService is null)
            return;

        await ftpService.StopAsync(cancellationToken);
        ftpService = null;
        serviceProvider?.DisposeAsync();
    }

Sometimes when I call StopAsync the server refuses to stop.

System.Net.Sockets.SocketException (10048): Only one usage of each socket address (protocol/network address/port) is normally permitted.
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at System.Net.Sockets.TcpListener.Start(Int32 backlog)
   at FubarDev.FtpServer.MultiBindingTcpListener.StartListening(IEnumerable`1 addresses, Int32 port)
   at FubarDev.FtpServer.MultiBindingTcpListener.StartAsync()
   at FubarDev.FtpServer.Networking.FtpServerListenerService.ExecuteAsync(CancellationToken cancellationToken)
   at FubarDev.FtpServer.Networking.PausableFtpService.RunAsync(IProgress`1 statusProgress)
   at System.Threading.Channels.AsyncOperation`1.GetResult(Int16 token)
   at FubarDev.FtpServer.FtpServer.ReadClientsAsync(ChannelReader`1 tcpClientReader, CancellationToken cancellationToken)
   at FubarDev.FtpServer.FtpServer.StopAsync(CancellationToken cancellationToken)
   at FubarDev.FtpServer.FtpServerHost.StopAsync(CancellationToken cancellationToken)

Frequent calls with delay dont work either :/

Any idea what the hell is wrong up there ?

fubar-coder commented 1 year ago

It seems that the internal FTP server task fails to start on all specified addresses and you see the shown error message when try to stop it. It would be interesting to see the IP addresses it tries to listen on.

Crashdummyy commented 1 year ago

It seems that the internal FTP server task fails to start on all specified addresses and you see the shown error message when try to stop it. It would be interesting to see the IP addresses it tries to listen on.

No the Server starts as expected. This exception is sometimes thrown when I try to stop it