FtpServer
FtpServer copied to clipboard
Problems encountered in using xamarin
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);
}
}
}
}

If the above error occurs, it is required to be an absolute path. How can this problem be solved?
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"));
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?
TBH: I don't know where the error comes from. Do you have a stack trace?