Path: redb-route/redb.Route.Sftp/SftpComponent.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.Sftp/SftpComponent.cs ---- using Microsoft.Extensions.Logging; using redb.Route.Abstractions; using redb.Route.Extensions; using redb.Route.Core; using redb.Route.GenericFile; namespace redb.Route.Sftp; /// /// SFTP transport component for redb.Route. /// Scheme: sftp. /// /// URI format: sftp:///remote/path?host=server&port=22&username=admin&password=secret /// /// /// Provides enterprise-grade SFTP integration powered by SSH.NET: /// polling consumer with glob filtering, idempotency, pre/post-move; /// atomic producer with temp-file upload, chmod, and auto-create directories. /// Supports password, public-key, and keyboard-interactive authentication plus proxy tunneling. /// /// public sealed class SftpComponent : ComponentBase { /// public override string Scheme => "sftp"; /// public override IEndpoint CreateEndpoint(EndpointUri uri) { ArgumentNullException.ThrowIfNull(uri); var options = new SftpEndpointOptions(); options.BindFromUri(uri.RawParameters); options.ResolveFilter(Context); // Named ConnectionFactory keeps the password / key passphrase / proxy password // out of the route URI. if (!string.IsNullOrEmpty(options.ConnectionFactory)) { // A set-but-unknown name fails loud -- never a silent fallback to URI params. var factory = Context.GetRequiredFromRegistry(options.ConnectionFactory); factory.ApplyTo(options, uri); } options.Validate(); return new SftpEndpoint(uri, this, options); } } /// /// SFTP endpoint. Creates either a consumer (for polling a remote directory) /// or a producer (for uploading files). The path part of the URI is the remote base directory. /// public sealed class SftpEndpoint : EndpointBase { /// Creates an SFTP endpoint. public SftpEndpoint(EndpointUri uri, SftpComponent component, SftpEndpointOptions options) : base(uri, component, options) { } /// The remote base directory path derived from the endpoint URI. public string RemotePath => NormalizeRemotePath(Uri.Path); /// Gets the endpoint options for external access. internal SftpEndpointOptions EndpointOptions => Options; /// public override IProducer CreateProducer() { return new SftpProducer(this, Options, new SftpFileOperations(Options)); } /// public override IConsumer CreateConsumer(IProcessor processor) { ArgumentNullException.ThrowIfNull(processor); return new SftpConsumer(this, processor, Options, new SftpFileOperations(Options)); } private static string NormalizeRemotePath(string path) { // Ensure leading slash for absolute SFTP paths if (string.IsNullOrEmpty(path)) return "/"; // Normalize double slashes while (path.Contains("//")) path = path.Replace("//", "/"); // Ensure leading slash if (!path.StartsWith('/')) path = "/" + path; // Remove trailing slash (unless root) if (path.Length > 1 && path.EndsWith('/')) path = path[..^1]; return path; } }