pub struct SmbShare { /* private fields */ }
Implementations§
Sourcepub fn new(
share: impl Into<String>,
username: impl Into<String>,
password: impl Into<String>,
mount_on: Option<char>,
) -> Self
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);
Sourcepub fn connect(&self, persist: bool, interactive: bool) -> Result<()>
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 ifmount_on
isNone
interactive
will prompt the user for a password instead of failing withError::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.
Sourcepub fn disconnect(&self, persist: bool, force: bool) -> Result<()>
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.