Path: redb-route/redb.Route.GenericFile/RemoteFileConnectionFactory.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.GenericFile/RemoteFileConnectionFactory.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
namespace redb.Route.GenericFile;
///
/// Base named connection factory for remote-file transports (FTP, SFTP). Register a concrete
/// subclass in the route registry and reference it by name from the endpoint URI
/// (connectionFactory=my-server) so server credentials never have to appear in the URI,
/// and therefore can never reach logs, telemetry, or the Tsak dashboard.
///
public abstract class RemoteFileConnectionFactory
{
/// Remote server hostname or IP.
public string Host { get; set; } = "localhost";
/// Server port (0 = protocol default).
public int Port { get; set; }
/// Username for authentication.
public string Username { get; set; } = "";
/// Password for authentication.
[Sensitive]
public string Password { get; set; } = "";
/// Connection timeout in milliseconds.
public int ConnectionTimeout { get; set; } = 30_000;
/// Operation timeout in milliseconds.
public int OperationTimeout { get; set; } = 60_000;
///
/// Copies the shared connection and credential settings onto the endpoint options, but only for
/// parameters the endpoint URI did not set explicitly — an inline URI value always wins, so
/// existing routes keep their behaviour. Subclasses override to add protocol-specific fields
/// and must call base.ApplyTo(...) first.
///
internal virtual void ApplyTo(RemoteFileEndpointOptions options, EndpointUri uri)
{
var supplied = uri.RawParameters;
if (!supplied.ContainsKey(nameof(options.Host))) options.Host = Host;
if (!supplied.ContainsKey(nameof(options.Port))) options.Port = Port;
if (!supplied.ContainsKey(nameof(options.Username))) options.Username = Username;
if (!supplied.ContainsKey(nameof(options.Password))) options.Password = Password;
if (!supplied.ContainsKey(nameof(options.ConnectionTimeout)))
options.ConnectionTimeout = ConnectionTimeout;
if (!supplied.ContainsKey(nameof(options.OperationTimeout)))
options.OperationTimeout = OperationTimeout;
}
}