FtpServer icon indicating copy to clipboard operation
FtpServer copied to clipboard

Problems encountered in using xamarin

Open qinjianzhanqing opened this issue 4 years ago • 3 comments

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?

qinjianzhanqing avatar Jun 09 '21 10:06 qinjianzhanqing

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"));

fubar-coder avatar Jun 09 '21 11:06 fubar-coder

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?

qinjianzhanqing avatar Jun 10 '21 00:06 qinjianzhanqing

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

fubar-coder avatar Jun 10 '21 08:06 fubar-coder