Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems encountered in using xamarin #117

Open
qinjianzhanqing opened this issue Jun 9, 2021 · 3 comments
Open

Problems encountered in using xamarin #117

qinjianzhanqing opened this issue Jun 9, 2021 · 3 comments

Comments

@qinjianzhanqing
Copy link

qinjianzhanqing commented Jun 9, 2021

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

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

@fubar-coder fubar-coder reopened this Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants