Sftpd.Backends.S3 (Sftpd v0.1.1)

Copy Markdown View Source

S3 storage backend for the SFTP server.

This backend supports efficient directory listings and optional streaming read and write callbacks for large file transfers.

S3 support is optional at the package level. Applications that use this backend must also depend on :ex_aws, :ex_aws_s3, :hackney, :sweet_xml, :jason, and :configparser_ex. When those dependencies are absent, init/1 returns {:error, :missing_s3_dependency}.

See the Backends extra in HexDocs for package-level backend guidance and Telemetry for the event reference emitted around S3-backed operations.

Summary

Types

S3 backend state containing bucket name, optional prefix, and AWS client module

Functions

Initialize the S3 backend.

Parse an HTTP date string (RFC 1123 format) into an Erlang datetime tuple.

Types

prefix()

@type prefix() :: String.t() | {:session, atom()}

S3 backend state containing bucket name, optional prefix, and AWS client module

state()

@type state() :: %{bucket: String.t(), prefix: prefix(), aws_client: module()}

writer_handle()

@type writer_handle() :: %{
  bucket: String.t(),
  key: String.t(),
  upload_id: String.t() | nil,
  next_offset: non_neg_integer(),
  next_part_number: pos_integer(),
  pending_chunks: :queue.queue(binary()),
  pending_size: non_neg_integer(),
  uploaded_parts: [{pos_integer(), binary()}]
}

Functions

init(opts)

@spec init(keyword()) :: {:ok, state()} | {:error, atom()}

Initialize the S3 backend.

Requires the :bucket option. :prefix scopes all object keys under a prefix, and :aws_client can override the ExAws-compatible request module.

Returns {:error, :missing_bucket} when :bucket is not provided. Returns {:error, :missing_s3_dependency} when ExAws.S3 is unavailable, which lets core-only applications compile and handle accidental S3 configuration without adding ExAws.

parse_http_date(date_string)

@spec parse_http_date(String.t()) :: :calendar.datetime()

Parse an HTTP date string (RFC 1123 format) into an Erlang datetime tuple.

Returns the current time if parsing fails.

Examples

iex> Sftpd.Backends.S3.parse_http_date("Sun, 06 Nov 1994 08:49:37 GMT")
{{1994, 11, 6}, {8, 49, 37}}