### Start Samba Container Source: https://github.com/afiffon/smb-rs/blob/main/crates/smb/tests/README.md Use this command to start the Samba container for integration testing. Ensure Docker is installed and configured. ```bash docker compose up [-d] ``` -------------------------------- ### Add Software RDMA NIC Source: https://github.com/afiffon/smb-rs/blob/main/crates/smb-transport/README.rdma.md Use this command to add a software RDMA NIC, for example, when your main NIC is ens18. Ensure the interface is active using 'rdma link show'. ```sh rdma link add rxe_ens18 type rxe netdev ens18 ``` -------------------------------- ### Async and Sync Main Function with `maybe_async` Source: https://github.com/afiffon/smb-rs/blob/main/crates/smb/docs/threading_models.md This example demonstrates how to write a main function that can be compiled for both async and synchronous execution using `maybe_async`. Conditional compilation (`cfg`) is used to select the appropriate `main` function based on the `async` feature. ```rust use smb::{Client, ClientConfig, UncPath, FileCreateArgs, FileAccessMask}; use std::str::FromStr; #[cfg(feature = "async")] // can also use [maybe_async::async_impl] #[tokio::main] async fn main() -> Result<(), Box> { do_main().await } #[cfg(not(feature = "async"))] // can also use [maybe_async::sync_impl] fn main() -> Result<(), Box> { do_main() } #[maybe_async::maybe_async] async fn do_main() -> Result<(), Box> { // instantiate the client let client = Client::new(ClientConfig::default()); // Connect to a share let target_path = UncPath::from_str(r"\\server\share").unwrap(); client.share_connect(&target_path, "username", "password".to_string()).await?; // And open a file on the server let file_to_open = target_path.with_path("file.txt"); let read_access= FileAccessMask::new().with_generic_read(true); let file_open_args = FileCreateArgs::make_open_existing(read_access); let file = client.create_file(&file_to_open, &file_open_args).await?; // now, you can do a bunch of operations against `file`, and close it at the end. Ok(()) } ``` -------------------------------- ### Connect to SMB Share and Read File Source: https://github.com/afiffon/smb-rs/blob/main/README.md Demonstrates how to instantiate the smb client, connect to a share, open an existing file with read permissions, read data from it, and close the file. Requires tokio runtime. ```rust use smb::{Client, ClientConfig, UncPath, FileCreateArgs, FileAccessMask, ReadAtChannel}; use std::str::FromStr; #[tokio::main] async fn main() -> Result<(), Box> { // instantiate the client let client = Client::new(ClientConfig::default()); // Connect to a share let target_path = UncPath::from_str(r"\\server\share").unwrap(); client.share_connect(&target_path, "username", "password".to_string()).await?; // And open a file on the server let file_to_open = target_path.with_path("file.txt"); let file_open_args = FileCreateArgs::make_open_existing(FileAccessMask::new().with_generic_read(true)); let resource = client.create_file(&file_to_open, &file_open_args).await?; // now, you can do a bunch of operations against `file`, and close it at the end. let file = resource.unwrap_file(); let mut data: [u8; 1024] = [0; 1024]; file.read_at(&mut data, 0).await?; // and close file.close().await?; Ok(()) } ``` -------------------------------- ### Connect to SMB Server and Open File Source: https://github.com/afiffon/smb-rs/blob/main/crates/smb/docs/index.md Instantiates a client, connects to a specified share with provided credentials, and opens an existing file with read access. Ensure the 'async' feature is enabled. ```rust use smb::{Client, ClientConfig, UncPath, FileCreateArgs, FileAccessMask}; use std::str::FromStr; # #[cfg(not(feature = "async"))] fn main() {} # #[cfg(feature = "async")] #[tokio::main] async fn main() -> Result<(), Box> { // instantiate the client let client = Client::new(ClientConfig::default()); // Connect to a share let target_path = UncPath::from_str(r"\\server\share").unwrap(); client.share_connect(&target_path, "username", "password".to_string()).await?; // And open a file on the server let file_to_open = target_path.with_path("file.txt"); let file_open_args = FileCreateArgs::make_open_existing(FileAccessMask::new().with_generic_read(true)); let file = client.create_file(&file_to_open, &file_open_args).await?; // now, you can do a bunch of operations against `file`, and close it at the end. Ok(()) } ``` -------------------------------- ### Display SMB-CLI Help Source: https://github.com/afiffon/smb-rs/blob/main/smb-cli/README.md Run this command to view the available subcommands and options for the SMB-CLI. ```sh cargo run -- --help ``` -------------------------------- ### Build SMB-CLI with Profiling Source: https://github.com/afiffon/smb-rs/blob/main/smb-cli/README.md Build the project with profiling enabled. This requires the 'profiling' feature to be activated. ```sh cargo build --profile profiling --features profiling ``` -------------------------------- ### Read and Write File Data Source: https://github.com/afiffon/smb-rs/blob/main/crates/smb/docs/index.md Reads data from a file into a buffer and writes data from a buffer to the file at specified offsets. Assumes the resource is a file and has been successfully opened. ```rust # use smb::*; # #[cfg(not(feature = "async"))] fn main() {} # #[cfg(feature = "async")] # #[tokio::main] # async fn main() -> Result<()> { # let client = Client::default(); # let mut file = client.create_file(&UncPath::new("")?, &FileCreateArgs::default()).await?; let file: File = file.unwrap_file(); let mut data: [u8; 1024] = [0; 1024]; file.read_at(&mut data, 0).await?; file.write_at(&data, 0).await?; # Ok(())} ``` -------------------------------- ### Determine SMB Resource Type Source: https://github.com/afiffon/smb-rs/blob/main/crates/smb/docs/index.md Checks the type of SMB resource (File, Directory, or Pipe) returned by a create_file operation using a match statement. This helps in handling different resource types appropriately. ```rust # use smb::*; # #[cfg(not(feature = "async"))] fn main() {} # #[tokio::main] # #[cfg(feature = "async")] # async fn main() -> Result<()> { # let client = Client::default(); # let mut file = client.create_file(&UncPath::new("")?, &FileCreateArgs::default()).await?; match &file { Resource::File(file) => { // We have a file } Resource::Directory(dir) => { // We have a directory } Resource::Pipe(pipe) => { // We have a pipe } } // Note: we could also use `.unwrap_file()` here, // or similar method provided by Resource to find out what kind of resource this is! # Ok(())} ``` -------------------------------- ### Close SMB File Resource Source: https://github.com/afiffon/smb-rs/blob/main/crates/smb/docs/index.md Closes an opened SMB file resource. This should be called after all operations on the file are completed to release server-side resources. ```rust # use smb::*; # #[cfg(not(feature = "async"))] fn main() {} # #[cfg(feature = "async")] # #[tokio::main] # async fn main() -> Result<()> { # let client = Client::default(); # let mut file = client.create_file(&UncPath::new("")?, &FileCreateArgs::default()).await?; # let file: File = file.unwrap_file(); file.close().await?; # Ok(())} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.