sftp

package module
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: BSD-3-Clause Imports: 16 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-filesystems/sftp

sftp

Go Reference CI

Pure-Go (CGO=0) SFTP server that exports any go-filesystems/interface Filesystem — so every driver in the family becomes reachable from any ordinary SFTP client, with nothing installed on the client side and nothing mounted.

No kernel extension. No FSKit entitlement. No cgo. No root, on either side.

Why SFTP

go-filesystems/nfs makes a driver mountable. Mounting is powerful and it has a price: it needs root on the client, a mount point, and an administrator's cooperation. SFTP asks for none of that.

An SFTP client is already everywhere, and it is already the thing people reach for:

sftp, scp ships with OpenSSH — every Linux, every macOS, Windows 10 and later
Cyberduck, Transmit, FileZilla, WinSCP ordinary desktop file browsers
VS Code, TRAMP edit a file in the image in place
GNOME Files (gvfs) mounts sftp:// as a plain user, no root

And the protocol brings what NFSv3 does not have at all: public-key authentication and encryption, built in rather than bolted on.

Timestamps. A driver with filesystem.TimesReader (interface v0.6.0) supplies each file's real atime and mtime, in stat and in the ls -l longname. SFTP v3 carries them as one flagged pair of unsigned 32-bit seconds (draft-ietf-secsh-filexfer-02): a missing atime is the mtime; a missing mtime CLEARS the flag ("the server did not say") and the longname shows ??? ?? ??:?? instead of a date; before 1970 clamps to 0 and after 2106 to 2^32-1. A driver without the capability still reports the server's start time. Tested against OpenSSH's sftp (ls -l).

Why it makes per-client isolation cheap

"SFTP would let us isolate clients in their own file, in user space, with a dedicated server."

One disk image per client. One process per client. Its own keys.

The isolation boundary is the image file plus the process — not a chroot, not permissions, not a uid. There is nothing to escape to, because the server holds exactly one Filesystem and has no way to name anything else. It never touches a host path, and the only paths it ever resolves are the ones clean has already clamped inside the image.

That is a property, not an aspiration, so it is tested: TestNoPathEscapesTheExport and TestNoSymlinkEscapesTheExport do not merely assert that an escape fails — they assert that it resolves to the file the image actually contains at the clamped path, which is the much stronger statement.

Serve is cheap to instantiate and cheap to run N times on one machine, which is what makes "a server per tenant" a real deployment shape rather than a slogan. It is a library first (the target is weft, the fleet's microVM cloud) and a standalone binary second.

Install

go get github.com/go-filesystems/sftp

Serving one

fsys, err := fat32.Open("disk.img", -1)
if err != nil {
	return err
}
defer fsys.Close()

srv, err := sftp.New(fsys, sftp.ReadWrite()) // read-only by default
if err != nil {
	return err
}

d, err := sshd.New(srv, sshd.Config{
	HostKeys:       []ssh.Signer{hostKey},   // yours; nothing is read from a fixed path
	AuthorizedKeys: []ssh.PublicKey{clientKey},
})
if err != nil {
	return err
}
return d.ListenAndServe("127.0.0.1:2222")

Then, from anything:

sftp -P 2222 user@127.0.0.1

Host keys and authorised keys are always supplied by the caller. This module opens no key file, consults no ~/.ssh, and has no "allow any key" switch — not even in the demo, because such switches get copied into deployments.

Who gets in

sshd.Config names every way in, and a Config that names none is refused with ErrNoAuthorizedKeys rather than read as "let everyone in":

field what it accepts
AuthorizedKeys a flat set of public keys, compared on their full wire form
PublicKeyFor a key, judged against the user name offering it
TrustedUserCAs user certificates signed by one of these CAs, the way OpenSSH's TrustedUserCAKeys does: x/crypto's CertChecker checks the signature, the validity window and that the user name is a principal
CertificateFor a certificate no trusted CA signed, such as an OpenPubkey (opkssh) one signed by the user's own key; the callback decides what that key is worth
Password a password, compared by the caller; nil means password authentication is not even offered

ServerFor, or ServerForLogin with the login's permissions (a certificate's extensions, or what CertificateFor returned), then chooses what each connection sees.

Critical options. On either certificate path the only critical option accepted is source-address; a certificate carrying any other (force-command, verify-required, ...) is refused, because a restriction this server does not act on is one its issuer believes holds and does not. source-address is enforced against the connection's address on both paths. On the CertificateFor path (since v0.5.1) it is put into the permissions whatever the callback returns, alongside the callback's own critical options; a callback that sets a different source-address has the login refused. The tests dial from 127.0.0.1, ::1 and 127.0.0.2, so a pin is matched against the connecting address, IPv6 included, and not merely against "loopback".

Layout

package depends on why
wire/ nothing but the standard library the v3 packet codec
. interface, wire the SFTP subsystem over a Filesystem
sshd/ ., go-filesystems/ssh (fork of golang.org/x/crypto/ssh) the SSH front-end

The codec is deliberately isolated. wire imports neither the filesystem interface nor the server — it is checked, not merely intended. The reason is that an sftp:// client transport may one day live in go-streamkit, and it would share this encoding; keeping the dependency edge absent now means that extraction is a move rather than a rewrite. go-filesystems/nfs made the same split with its xdr/ and rpc/ packages.

Cryptography is not reimplemented: the transport is github.com/go-filesystems/ssh, a fork of golang.org/x/crypto/ssh with one change: it flushes once per channel Write through a 64 KiB buffer instead of once per packet through a 4 KiB one, so a 32 KiB packet is one write(2) and not two (96 writes per MiB sent become 32). The fork's API is that of x/crypto/ssh and it is meant to go back upstream. The SFTP subsystem itself (draft-ietf-secsh-filexfer-02, version 3 — what every client actually speaks) is implemented here, because the protocol is the thing this repository is for.

Extensions

Two, both answered, and nothing advertised that is not:

  • limits@openssh.com (since v0.6.0): the server's packet, read and write lengths and open-handle bound, so OpenSSH's sftp reads and writes up to 255 KiB per request instead of 32 KiB (about +25% measured with OpenSSH 10.3). One session holds at most 1024 open handles, and the directory listings kept by its open OPENDIR handles hold at most 262144 entries between them (one listing is always allowed, however large).
  • copy-data (since v0.7.0), what OpenSSH 9.0+'s sftp cp sends: a copy from one open handle into another on the server, through hostcopy -- a megabyte at a time, or copy_file_range(2) in the kernel between two files of the host, which shares blocks on btrfs and XFS. Offered on a writable export whose driver opens files; one file read and written at once is refused, as OpenSSH does. sftp cp of 256 MiB through go-fileshare: 0.21 s, handshake included, where the client used to download and upload it.

Concurrent requests

A session answers up to 64 requests at once (sftp.WithMaxInFlight(n); 1 is the one-at-a-time behaviour of v0.7.0), which is what a client that pipelines 64 READs, as OpenSSH's sftp does, needs. The work is concurrent; the replies leave in the order the requests arrived. The draft would allow any order (draft-ietf-secsh-filexfer-02 §6.1, §7), but OpenSSH's client treats a reordered reply as a reason to refuse get -a/reget ("server reordered requests", sftp-client.c:1795 and 1856), and OpenSSH's own server never reorders (sftp-server.c process()).

The mechanism (bounds, range ordering, barriers, reply order, the filesystem lock) is the shared module go-filesystems/inflight, also used by the NFS and SMB servers; this module keeps what is SFTP: which requests may overlap and which byte range each touches.

  • Parallel: READ and WRITE, through the driver's File.ReadAt and WritableFile.WriteAt, which the interface module documents as safe for concurrent use (writes on non-overlapping ranges only).
  • Ordered: a READ or WRITE waits for any request in progress on the same file whose byte range overlaps it and where one of the two is a write, across every session of the server. A write to a driver with no WritableFile rewrites the whole file and so waits for everything on it.
  • Barriers: every other request (OPEN, CLOSE, FSTAT, SETSTAT, READDIR, STAT, RENAME, ...) waits for all requests in flight, runs alone, and only then is the next packet read. A CLOSE therefore follows every pending operation on its handle.
  • Driver contract: path-based calls, Truncate, Sync and Close hold the filesystem lock exclusively, as before; ReadAt/WriteAt hold it shared. A host-directory embedder whose Stat, ListDir, ReadFile and ReadLink are safe in parallel can say so with sftp.PathOpsConcurrent().
  • Bounded, per session and server-wide: a slot (WithMaxInFlight, 64) and a token of the server's budget (WithMaxInFlightTotal, 256 across ALL sessions) are taken before a packet is read and freed when its reply is written, so a client that pipelines faster than the server answers, or does not read its replies, waits in the transport. Memory is at most 3 x total x the packet limit (about 200 MiB at the defaults), however many sessions there are. An idle session holds nothing. This is OpenSSH's own rule (sftp-server.c:2064-2066, 2121: no input is read while the output queue cannot take a maximum-size message), with knfsd's thread pool and Samba's aio max threads as the shared budget. A peer that never reads keeps its tokens, as it would keep a knfsd thread: close stalled connections. The rest of a packet has WithPacketTimeout (30 s) to arrive once its first byte has, since the request holds its slot and token meanwhile; a packet that is late ends the session (the stream is closed, or given a past read deadline).
  • Replies coalesced: replies that are ready together (already in request order) are written in ONE write of at most WithReplyBatch bytes (256 KiB by default; a negative value writes each on its own). On an SSH channel this turns a 32 KiB READ reply, which was one full packet plus a 13-byte tail packet, into full packets, and OpenSSH's sftp-server does the same by writing its whole output queue at once (sftp-server.c:2073-2113). Slots are freed only after the write, so the memory bound above is unchanged; a session adds one buffer of at most the batch size. A READ is read from the file straight into its reply packet.

The write path, measured

SSH_FXP_READ(handle, offset, len) lands exactly on filesystem.Opener / File.ReadAt, and SSH_FXP_WRITE(handle, offset, data) lands exactly on filesystem.WritableFile (io.WriterAt + Truncate + Sync), published in interface v0.3.0 and implemented by fat32 v0.3.0. Both are optional capabilities, probed with a type assertion.

When a driver has not got WritableFile, the only write the base contract offers is WriteFile(path, data, perm), which replaces the file whole. A write at an offset then costs read-all + splice + write-all, per request — so streaming a file in fixed-size chunks is O(n²).

That cost is measured, not asserted. 2 MiB through the real OpenSSH client in its own 32 KiB chunks, Apple M-series, task measure:

path time throughput
WritableFile (positional) 46 ms 44 066 kB/s
WriteFile fallback (splice) 1.021 s 2 007 kB/s

22× slower — and the gap grows with the file, which is the part that matters:

size time throughput cost of doubling
1 MiB 182 ms 5 638 kB/s
2 MiB 1.109 s 1 846 kB/s 6.11×
4 MiB 8.114 s 505 kB/s 7.31×

Worse than the 4× a purely quadratic term predicts, because the driver's WriteFile also rewalks the cluster chain each time. go-filesystems/nfs measured the identical construction at 90 kB/s, with a soft-mounted client giving up with EIO partway through. This is why the fallback is documented as a wall and not as a slow path — and why it is deliberately not hidden behind a write-back cache, which would make the benchmark look fine while turning "the server acknowledged this write" into a durability claim it cannot honour.

Verification

"It compiles" is not evidence. The gate is 100% of statements, error branches included, on both modules — but the claim that matters is that a real client agrees, so fat32demo/ serves a genuine driver-formatted image to the sftp binary that ships with OpenSSH and compares on content:

  • ls, then get of a 1 MiB file — sha256 of what the client received equals sha256 of what the driver returns from ReadFile, not what the test wrote.
  • reget resuming at offset 700 000, the only step that exercises a non-zero READ offset: a plain get always starts at zero, so a server that ignored the offset entirely would pass everything else.
  • put of 64 KiB, verified by reopening the image and reading it back through the driver, so the assertion is about what reached the medium rather than state the live server still holds.
  • a put against a read-only export must fail and leave nothing behind.

The wire is big-endian, so CI runs the test binaries under QEMU on s390x as well as riscv64, loong64 and ppc64le — s390x being the arch on which a forgotten binary.BigEndian would still pass on the developer's machine.

Every key in the test suite is generated in memory, or with ssh-keygen into t.TempDir() outside every repository, and removed when the test ends. No key is read from or written to a fixed location, .gitignore refuses key shapes as a net, and CI fails the build if any key material or image survives in the work tree.

Security posture

  • Bind to loopback unless you have decided otherwise.
  • Read-only is the default; sftp.ReadWrite() is opt-in, because an accidental write to a forensic or build artefact is unrecoverable.
  • Nobody is let in by default. Every key, CA and callback is the caller's, and a Config that names no way in is refused; password authentication exists only when the caller supplies Password.
  • A server can reach nothing but the one Filesystem it was given. No host path, no .. escape, no symlink out of the image.
  • An offset a client sends cannot size an allocation. On a driver without WritableFile, a WRITE rewrites the whole file at its new end; that path grows a file by at most 8 MiB past its end and to at most 1 GiB, as go-filesystems/nfs and smb do, and answers SSH_FX_FAILURE beyond. ⛔ Its only bound used to be 1 TiB: one 1-byte WRITE at offset 2³⁹ asked for 512 GiB. A SETSTAT size above 2⁶³−1 is refused instead of reaching the driver as a negative number. Packets are capped at 260 KiB and READs at 255 KiB, as before.

Licence

BSD-3-Clause.

Documentation

Overview

Package sftp implements an SFTP version 3 server (draft-ietf-secsh-filexfer-02) that exports any github.com/go-filesystems/interface.Filesystem.

Every driver in the family — ext4, xfs, btrfs, zfs, ntfs, fat32, exfat, hfsplus, apfs, iso9660, squashfs, ufs, ffs, uefi, oci — becomes something a person can reach from a file manager, an editor or a shell, over one TCP port, with SSH keys and encryption, from a pure-Go binary with no cgo.

Why SFTP

The client already exists, everywhere, and nobody has to install it.

  • `sftp` on the command line ships with OpenSSH, which is present on macOS, on every Linux distribution, on the BSDs, and on Windows 10 and later as an optional feature that is on by default in current builds.
  • Graphical clients are abundant and free or cheap: Cyberduck, FileZilla, WinSCP, Transmit.
  • Editors speak it natively: VS Code, the JetBrains IDEs, Emacs by way of TRAMP.
  • GNOME mounts sftp:// through gvfs as an ordinary unprivileged user, with no root and no entry in the kernel's mount table.

And the security is not bolted on. Authentication is SSH public keys and the channel is encrypted, both from golang.org/x/crypto/ssh — see github.com/go-filesystems/sftp/sshd. NFSv3, the sibling of this module, has neither: its AUTH_UNIX credentials are claims a client makes about itself and the wire cannot disagree. It is one TCP port, so a firewall can reason about it, and nothing needs privilege on either side: no mount, no kernel extension, no FSKit entitlement, no root.

The isolation this is built for

One image file per client, one server process per client, each with its own keys. The isolation boundary is the image file plus the process — not a chroot, not uid mapping, not namespaces.

That is why Server takes exactly one github.com/go-filesystems/interface.Filesystem and holds no other capability. It never touches the host filesystem, never resolves a path against anything but the driver it was handed, and cannot be induced to: a client path is cleaned with ".." clamped at the root before it reaches the driver, so no sequence of components names anything outside the image, and a symbolic link inside the image resolves inside the image because the driver is the only thing doing the resolving. The tests assert this directly rather than leaving it to be inferred.

A Server is cheap: no goroutine until a session arrives, no listener of its own, no global state. Running a hundred of them on one machine, one per tenant, is the intended shape, and Server.Serve is deliberately handed a stream rather than a listener so that an embedding program — a microVM supervisor, say — can wire it into an SSH server it already runs.

Serving one

fsys, err := fat32.Open("tenant.img", -1)
if err != nil {
	return err
}
defer fsys.Close()

srv, err := sftp.New(fsys)          // read-only by default
if err != nil {
	return err
}
// Then either hand srv.Serve a stream you own, or let the sshd
// subpackage own the SSH side:
d, err := sshd.New(srv, sshd.Config{HostKeys: ..., AuthorizedKeys: ...})

Two honest gaps, both in the contract and not in this server

Reads. github.com/go-filesystems/interface.Opener is exactly the shape of SSH_FXP_READ: OpenFile(path) returns a File whose ReadAt(buf, off) answers the request as asked. This module uses it when a driver has it. At the time of writing NO driver in the fleet implements it, so in practice every read goes through the fallback, which calls ReadFile — materialising the WHOLE file — once per READ request. An OpenSSH client reads in 32 KiB chunks, so fetching an n-byte file costs n/32768 full-file reads: quadratic. That is measured in the README rather than described.

The tempting fix — read the file once when the handle is opened and serve reads from that copy — is not taken, because it trades a quadratic time cost for a linear MEMORY cost and a 4 GiB image file becomes 4 GiB of resident memory in a process meant to run a hundred times over. The real fix is a driver implementing Opener, and leaving the cost visible is what keeps that pressure where it belongs.

Writes. SSH_FXP_WRITE carries an offset, and the base contract has only WriteFile, which replaces a file whole. A write at an offset therefore becomes read-modify-write of the entire file: O(filesize) per request, and O(filesize²) for a client streaming a file in chunks. This is the same wall github.com/go-filesystems/nfs hit and measured at 90 kB/s. Exports are consequently READ-ONLY BY DEFAULT — see ReadWrite — and the number for this module is in the README.

The escape is WritableFile: a File that also has WriteAt, Truncate and Sync. When a driver's File satisfies it, writes go to the offset directly and the wall disappears. The probe is here and tested; the implementations belong in the drivers.

Index

Constants

View Source
const DefaultMaxInFlight = 64

DefaultMaxInFlight is how many requests a session may have in progress at once unless WithMaxInFlight says otherwise: OpenSSH's sftp client keeps 64 outstanding (sftp-client.c, DEFAULT_NUM_REQUESTS).

View Source
const DefaultMaxInFlightTotal = 256

DefaultMaxInFlightTotal is the server-wide ceiling on requests in flight across every session unless WithMaxInFlightTotal says otherwise.

View Source
const DefaultPacketTimeout = 30 * time.Second

DefaultPacketTimeout is how long the rest of a packet may take to arrive once its first byte has, unless WithPacketTimeout says otherwise.

View Source
const DefaultReplyBatch = inflight.DefaultBatch

DefaultReplyBatch is how many bytes of replies a session coalesces into one write of its channel unless WithReplyBatch says otherwise: eight 32 KiB SSH packets.

View Source
const MaxInFlightLimit = 1024

MaxInFlightLimit is the ceiling WithMaxInFlight is clamped to.

Variables

View Source
var ErrNilFilesystem = errors.New("sftp: nil filesystem")

ErrNilFilesystem reports New called with no filesystem.

It is caught at construction because the alternative is a nil dereference on the first client request — long after the mistake, in a per-session goroutine, with no recover, taking down every other tenant the process is serving.

View Source
var ErrNoInit = errors.New("sftp: first packet was not SSH_FXP_INIT")

ErrNoInit reports a peer whose first packet was not SSH_FXP_INIT.

The session cannot continue: version negotiation is the only thing that establishes what the following bytes mean, so guessing would be worse than stopping.

View Source
var ErrVersion = errors.New("sftp: unsupported client protocol version")

ErrVersion reports a peer demanding a protocol version this server cannot speak. See wire.Version.

Functions

This section is empty.

Types

type Option

type Option func(*Server)

Option configures a Server.

func PathOpsConcurrent added in v0.8.0

func PathOpsConcurrent() Option

PathOpsConcurrent asserts that the driver's read-only path calls (Stat, ListDir, ReadFile, ReadLink) may run concurrently with each other and with File I/O, which lets the server run them in parallel. The interface module does not promise it, so the embedder has to: it is right for a host directory (os calls), wrong for a driver with a shared cursor or cache.

func ReadWrite

func ReadWrite() Option

ReadWrite makes the export writable.

Exports are READ-ONLY BY DEFAULT, for two reasons that both point the same way. Most of what this module is pointed at is a forensic or build artefact, and an accidental write to one is unrecoverable. And until a driver's File implements WritableFile, every write at a non-zero offset is a read-modify-write of the entire file — see the package documentation and the measurement in the README. Opting in should be a decision, not a default.

func WithMaxInFlight added in v0.8.0

func WithMaxInFlight(n int) Option

WithMaxInFlight bounds how many requests one session processes at once.

The bound is enforced BEFORE a request is read: the session takes one of n buffers first, and when none is free it stops reading, so a client that pipelines faster than the server answers waits in TCP's window instead of in this process's memory. Memory per session is at most n packets in and n replies out. 1 restores v0.7.0's one-request-at-a-time behaviour; a non-positive value means DefaultMaxInFlight.

func WithMaxInFlightTotal added in v0.9.0

func WithMaxInFlightTotal(n int) Option

WithMaxInFlightTotal bounds the requests in flight across ALL sessions of the server, the figure a host serving many clients sizes memory by: each request in flight holds up to one packet in, one reply out and one read buffer, so memory is at most 3 x n x the packet limit (about 200 MiB at the defaults), however many sessions there are. A session that would exceed it stops reading its input until another request is answered, as OpenSSH's sftp-server stops reading while its output queue cannot take a maximum-size message (sftp-server.c, process_requests). A peer that does not read its replies keeps its tokens: the same is true of knfsd's threads and Samba's `aio max threads`, and the answer there is the same, to close idle or stalled connections. A non-positive value means DefaultMaxInFlightTotal.

func WithMaxPacket

func WithMaxPacket(n int) Option

WithMaxPacket caps the size of a single SFTP packet, in bytes, counting the type byte and payload.

The default, wire.MaxPacket, accepts everything OpenSSH's client sends including its largest -B setting. Lowering it is how a host running many tenants bounds the memory any one session can make it hold. A non-positive value restores the default.

func WithPacketTimeout added in v0.10.1

func WithPacketTimeout(d time.Duration) Option

WithPacketTimeout bounds how long the rest of a packet may take once its first byte has arrived. The request holds a slot and a token of the server-wide budget meanwhile, so without a bound a client that sends a length and stops holds them for ever. A packet that is not complete in time ends the session: the stream is closed (an SSH channel) or given a past read deadline (a net.Conn); a stream with neither is not interrupted. Zero means DefaultPacketTimeout; a negative value disables it. Waiting for the NEXT packet is not bounded and holds nothing.

func WithReplyBatch added in v0.11.0

func WithReplyBatch(n int) Option

WithReplyBatch bounds the bytes of replies that leave in one write. Replies that are ready together (they already leave in request order) are copied end to end into one buffer and written once, so the SSH channel splits the bytes into full packets instead of one short tail packet per reply, and a net.Conn pays one syscall for several replies, as OpenSSH's sftp-server does by writing its whole output queue at once (sftp-server.c, process_requests).

Memory is unchanged: a reply's slot and token are released only after the write, so the bytes held are what WithMaxInFlight and WithMaxInFlightTotal already count; the session adds one buffer of at most n bytes. Zero means DefaultReplyBatch; a negative value writes each reply on its own.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server exports one github.com/go-filesystems/interface.Filesystem over SFTP version 3.

One Server holds exactly one filesystem and no other capability. It has no listener, no goroutine and no global state until a session is handed to Server.Serve, which is what makes running one per tenant — the shape this module is built for — cheap rather than aspirational.

A Server is safe for concurrent use by any number of sessions.

func New

func New(fsys filesystem.Filesystem, opts ...Option) (*Server, error)

New returns a Server exporting fsys, read-only unless ReadWrite is given.

func (*Server) ReadOnly

func (s *Server) ReadOnly() bool

ReadOnly reports whether the export refuses mutating operations.

func (*Server) Serve

func (s *Server) Serve(rw io.ReadWriter) error

Serve runs one SFTP session over rw until the peer closes it or the stream fails, and returns nil on a clean close.

rw is one client's SFTP channel: in the ordinary case the SSH subsystem channel opened by github.com/go-filesystems/sftp/sshd, but deliberately only an io.ReadWriter, so a program that already runs an SSH server can hand this its own channel, and a test can hand it a pipe. Serve does not close rw — it did not open it.

Every handle the session opened is released before Serve returns, including when the client vanishes mid-transfer, which is what killing an `sftp` process does.

type TimeStat

type TimeStat interface {
	ModTime() int64 // seconds since the Unix epoch
}

TimeStat is the optional capability a driver's github.com/go-filesystems/interface.Stat may implement to report a real modification time.

It is the older probe, kept for a Stat that carries its own time. A filesystem with filesystem.TimesReader (interface v0.6.0) takes precedence over it (see attrsAt), and a driver with neither carries the server's start time in atime and mtime for every file.

type WritableFile

type WritableFile = filesystem.WritableFile

WritableFile is the capability that removes this module's write wall.

It is an open file that can be written AT AN OFFSET, which is exactly what SSH_FXP_WRITE(handle, offset, data) asks for, and exactly what the base github.com/go-filesystems/interface.Filesystem contract cannot express: that contract's only write is WriteFile, which replaces a file WHOLE. So serving a 32 KiB write into the middle of a 100 MiB file without this capability means reading 100 MiB, splicing 32 KiB in, and writing 100 MiB back — per request. See [writeSplice] and the README for the measurement of both paths.

It is an alias for github.com/go-filesystems/interface.WritableFile, published in interface v0.3.0, rather than a local redeclaration. The alias exists purely so that this package's own documentation has somewhere to explain what the capability means TO AN SFTP SERVER — which is not the same question as what it means to the interface module — while the type itself stays the fleet's one canonical definition. A driver satisfies it or does not; there is no second contract here to drift out of sync.

This module never implements it. It probes for it on the File returned by github.com/go-filesystems/interface.Opener, uses it when present, and falls back to read-modify-write with a documented cost when absent.

Directories

Path Synopsis
fat32demo module
Package sshd is the SSH front-end for github.com/go-filesystems/sftp: it authenticates clients with public keys, accepts the "sftp" subsystem, and hands the resulting channel to the SFTP server.
Package sshd is the SSH front-end for github.com/go-filesystems/sftp: it authenticates clients with public keys, accepts the "sftp" subsystem, and hands the resulting channel to the SFTP server.
Package wire is the SFTP version 3 codec: packet framing, message types, and the SSH binary encoding they are built from.
Package wire is the SFTP version 3 codec: packet framing, message types, and the SSH binary encoding they are built from.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址