7 unstable releases (3 breaking)

new 0.4.3 Mar 27, 2025
0.4.2 Mar 22, 2025
0.3.0 Mar 8, 2025
0.2.0 Mar 1, 2025
0.1.0 Feb 7, 2025

#1510 in Network programming

Download history 94/week @ 2025-02-02 21/week @ 2025-02-09 10/week @ 2025-02-16 79/week @ 2025-02-23 169/week @ 2025-03-02 69/week @ 2025-03-09 273/week @ 2025-03-16 181/week @ 2025-03-23

762 downloads per month

MIT license

515KB
13K SLoC

smb-rs: The SMB2 Client in Rust

Build Crates.io Docs.rs

This project is the first rust implementation of SMB2 & 3 client -- the protocol that powers Windows file sharing and remote services. The project is designed to be a library, but also includes a CLI tool for basic operations.

While most current implementations are mostly bindings to C libraries (such as libsmb2, samba, or windows' own libraries), this project is a full implementation in Rust, with no dependencies on C libraries!

Getting started

Running the project is as simple as:

cargo run -- --help

Check out the info and the copy sub-commands for more information.

For advanced usage, and crate usage, see the Advanced Usage section.

Features

General

  • ✅ SMB 2.X & 3.X support.
  • ✅ Full file operations support.
  • ✅ Async + Multi-threaded + Single-threaded backends.
  • ✅ Support for all file operations.
  • ✅ Compression + Encryption support.
  • ✅ Windows, Linux & MacOS support.
  • ✅ CLI tool for basic operations.

You are welcome to see the project's roadmap in the GitHub Project.

Dialect Support

Dialect Supported Notes
3.1.1
3.0.2
3.0
2.1
2.0.2

Algorithm Support

Type Algorithm Feature Name
Signing * sign
Signing HMAC_SHA256 sign_hmac
Signing AES-128-GCM sign_gmac
Signing AES-128-CCM sign_cmac
Encryption * encrypt
Encryption AES-128-CCM encrypt_aes128ccm
Encryption AES-128-GCM encrypt_aes128gcm
Encryption AES-256-CCM encrypt_aes256ccm
Encryption AES-256-GCM encrypt_aes256gcm
Compression * compress
Compression LZ4 compress_lz4
Compression Pattern_V1 🟡 compress_pattern_v1*
Compression LZNT1
Compression LZ77
Compression LZ77+Huffman

[!NOTE] Some of SMB's suported compression algorithms are missing, since no proper crates are available for them.

Advanced Usage

Using the library

Check out the Connection struct, exported from the smb crate, to initiate a connection to an SMB server:

use smb::Connection;
let connection = Connection::build(Default::default());
connection.connect("10.0.0.1:445").await?;
let session = connection.authenticate(&"user", "password".to_string()).await?;
let tree = session.tree_connect("share").await?;
let file = tree.create("file.txt", ...).await?;

Switch Threading model

The project supports async, multi-threaded, and single-threaded backends. The async backend is the default one, but you can enable the other backends by using the following features:

  • async: Enables the async backend (default)
  • single_threaded: Enables the single-threaded backend. Must disable default features.
  • multi_threaded: Enables the multi-threaded backend. Must disable default features.

For example, to enable the multi-threaded backend, you can run:

cargo run --no-default-feature --features "multi_threaded,sign,encrypt,compress" -- --help

If you're using the crate, you can enable the features in your Cargo.toml file:

[dependencies]
smb = { version = "0.1", features = ["multi_threaded", "sign", ...], no-default-features = true }

Dependencies

~17–46MB
~701K SLoC