Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Quick start

Install

cargo add smb-server
FeatureDefaultAdds
localfsonLocalFsBackend
discoveryoffmDNS and WS-Discovery announcements
s3offS3Backend
encryptionoffEncryptedBackend
[dependencies]
smb-server = { version = "0.12", features = ["discovery"] }

Serve a directory

use smb_server::{Access, LocalFsBackend, Share, SmbServer};

let server = SmbServer::builder()
    .listen("0.0.0.0:4445".parse()?)
    .user("alice", "password")
    .share(
        Share::new("home", LocalFsBackend::new("/srv/home")?)
            .user("alice", Access::ReadWrite),
    )
    .build()?;

server.bind().await?;
server.serve().await?;

Stop

Call server.shutdown(), or use server.shutdown_handle() from another task. Once triggered, serve():

  • stops accepting new connections
  • closes each active connection after its current request finishes
  • returns once every connection and disconnected durable handle has closed

Run the example

cargo run -p minimal-smb-example

The example listens on 127.0.0.1:4445 and serves directories under smb-example in the system temp directory.

ShareAccess
publicanonymous read-write
mediaanonymous read-only
homealice read-write, bob read-only
VariableEffect
SMB_LISTENListen address
SMB_ROOTRoot directory for the shares
SMB_PASSWORDPassword for alice and bob. If unset, a password is generated and logged at startup
SMB_DISCOVERY=1Announce the server on the network. Requires --features discovery and a non-loopback address
SMB_STREAMS=0Disable named streams
SMB_COPY=0Disable server-side copy
SMB_S3_BUCKETServe this S3 bucket as the only share (s3). Requires --features s3. See backends
SMB_ENCRYPTION_KEY64-hex-digit encryption key. Adds an encrypted vault share, or encrypts s3 when SMB_S3_BUCKET is also set. Requires --features encryption. See encrypted storage
SMB_DISCOVERY=1 SMB_LISTEN='[::]:4445' cargo run -p minimal-smb-example --features discovery