FubarDevelopment / FtpServer

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

Problems encountered in using xamarin #117

Open qinjianzhanqing opened 3 years ago

qinjianzhanqing commented 3 years ago
public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            this.Appearing += MainPage_Appearing;
        }

        private void MainPage_Appearing(object sender, EventArgs e)
        {
            var hostBuilder = new HostBuilder()
             .UseConsoleLifetime()
             .ConfigureServices(
                  (hostContext, services) =>
                  {
                      services
                         .AddFtpServer(opt => opt
                             .UseDotNetFileSystem()
                             .EnableAnonymousAuthentication())
                         .AddHostedService<HostedFtpService>();
                  });

            var host = hostBuilder.Build();
            host.RunAsync();
        }
        /// <summary>
        /// Generic host for the FTP server.
        /// </summary>
        private class HostedFtpService : IHostedService
        {
            private readonly IFtpServerHost _ftpServerHost;

            /// <summary>
            /// Initializes a new instance of the <see cref="HostedFtpService"/> class.
            /// </summary>
            /// <param name="ftpServerHost">The FTP server host that gets wrapped as a hosted service.</param>
            public HostedFtpService(
                IFtpServerHost ftpServerHost)
            {
                _ftpServerHost = ftpServerHost;
            }

            /// <inheritdoc />
            public Task StartAsync(CancellationToken cancellationToken)
            {
                return _ftpServerHost.StartAsync(cancellationToken);
            }

            /// <inheritdoc />
            public Task StopAsync(CancellationToken cancellationToken)
            {
                return _ftpServerHost.StopAsync(cancellationToken);
            }
        }
    }
}

image

If the above error occurs, it is required to be an absolute path. How can this problem be solved?

fubar-coder commented 3 years ago

It seems that you forgot to configure the root path for the FTP server. Here's an example from the README.md.

services.Configure<DotNetFileSystemOptions>(opt => opt
    .RootPath = Path.Combine(Path.GetTempPath(), "TestFtpServer"));
qinjianzhanqing commented 3 years ago

It seems that you forgot to configure the root path for the FTP server. Here's an example from the README.md.

services.Configure<DotNetFileSystemOptions>(opt => opt
    .RootPath = Path.Combine(Path.GetTempPath(), "TestFtpServer"));

I've configured the root path, but I still can't use it. I developed an Android program with xamarin. Is it related to the Android system?

fubar-coder commented 3 years ago

TBH: I don't know where the error comes from. Do you have a stack trace?