Struct SmbShare

Source
pub struct SmbShare { /* private fields */ }

Implementations§

Source§

impl SmbShare

Source

pub fn new( share: impl Into<String>, username: impl Into<String>, password: impl Into<String>, mount_on: Option<char>, ) -> Self

Create an SmbShare representation to connect to.

Optionally specify mount_on to map the SMB share to a local device. Otherwise it will be a deviceless connection. Case insensitive.

§Example
let share = sambrs::SmbShare::new(r"\\server.local\share", r"LOGONDOMAIN\user", "pass", None);
Source

pub fn connect(&self, persist: bool, interactive: bool) -> Result<()>

Connect to the SMB share. Connecting multiple times works fine in deviceless mode but fails with a local mount point.

  • persist will remember the connection and restore when the user logs off and on again. No-op if mount_on is None
  • interactive will prompt the user for a password instead of failing with Error::InvalidPassword
§Some excerpts from the Microsoft docs

persist (CONNECT_UPDATE_PROFILE): The network resource connection should be remembered. If this bit flag is set, the operating system automatically attempts to restore the connection when the user logs on.

The operating system remembers only successful connections that redirect local devices. It does not remember connections that are unsuccessful or deviceless connections. (A deviceless connection occurs when the lpLocalName member is NULL or points to an empty string.)

If this bit flag is clear, the operating system does not try to restore the connection when the user logs on.

!persist (CONNECT_TEMPORARY): The network resource connection should not be remembered. If this flag is set, the operating system will not attempt to restore the connection when the user logs on again.

interactive (CONNECT_INTERACTIVE): If this flag is set, the operating system may interact with the user for authentication purposes.

§Errors

This method will error if Windows is unable to connect to the SMB share.

Source

pub fn disconnect(&self, persist: bool, force: bool) -> Result<()>

Disconnect from the SMB share.

persist (CONNECT_UPDATE_PROFILE): The system updates the user profile with the information that the connection is no longer a persistent one. The system will not restore this connection during subsequent logon operations. (Disconnecting resources using remote names has no effect on persistent connections.)

force: Specifies whether the disconnection should occur if there are open files or jobs on the connection. If this parameter is FALSE, the function fails if there are open files or jobs.

§Errors

This method will return an error if Windows is unable to disconnect from the smb share.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more