Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sambrs

A tiny ergonomic wrapper around WNetAddConnection2W and WNetCancelConnection2W. The goal is to offer an easy to use interface to connect to SMB network shares on Windows.

Sam -> SMB -> Rust -> Samba is taken!? -> sambrs

Features

  • Simple and ergonomic interface to connect to SMB network shares.
  • Support for specifying a local Windows mount point.
  • Options to persist connections across user login sessions.
  • Interactive mode for password prompts.

Installation

Add this to your Cargo.toml:

[dependencies]
sambrs = "0.1"

Usage

Instantiate an SmbShare with an optional local Windows mount point and establish a connection.

When calling the connect method, you have the option to persist the connection across user login sessions and to enable interactive mode. Interactive mode will block until the user either provides a correct password or cancels, resulting in a Canceled error.

use sambrs::SmbShare;

fn main() {
    let share = SmbShare::new(r"\\server\share", "user", "pass", Some('D'));

    match share.connect(false, false) {
        Ok(()) => println!("Connected successfully!"),
        Err(e) => eprintln!("Failed to connect: {}", e),
    }

    // use std::fs as if D:\ was a local directory
    dbg!(std::fs::metadata(r"D:\").unwrap().is_dir());
}

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Special Thanks

Special thanks to Christian Visintin for his informative blog post on accessing SMB shares with Rust on Windows. If you need a fully-featured remote file access solution that works across multiple protocols, you should definitely check out his project remotefs.

Continuous Integration

This repository includes a GitHub Actions workflow that runs on Windows (windows-latest) and performs:

  • cargo fmt -- --check
  • cargo clippy -- -D warnings
  • cargo test --all

The workflow file is .github/workflows/ci.yml.

Tests

Some tests in this crate require access to a real SMB share and therefore are marked with #[ignore] by default. To run all tests including ignored ones (only on Windows with a proper SMB environment), use:

cargo test -- --ignored

Run only the fast unit tests (default) with:

cargo test

About

Clone from https://github.com/samvdst/sambrs, I modified WNetAddConnection2A to WNetAddConnection2W for Unicode support. A tiny ergonomic wrapper around WNetAddConnection2W to connect to SMB shares on Windows.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages