Lightweight wrapper for dynamic access to Windows shares on Linux via CIFS protocol
$ dotnet add package AZ.CifsMountCifsMount is a lightweight .NET library that allows you to automatically mount shared Windows folders on Linux using the cifs-utils
You can install CifsMount with NuGet:
Install-Package CifsMount
cifs-utils dependency
sudo apt -y install cifs-utils
mount and umount commands for the user. For example, test user (change for your user!)
sudo bash -c 'cat >> /etc/sudoers <<< "test ALL=(ALL) NOPASSWD: /usr/bin/mount, /usr/bin/umount"'
sudo mkdir -p /mnt/my_mount
sudo chown test:test -R /mnt/my_mount
CifsMountClient and Mount() target foldervar shareDirectory = "//server123.domain.xyz/RootFolder/SubFolder"; // Windows shared folder
var targetDirectory = "/mnt/my_mount/"; // Local mounted directory
var options = new CifsMountOptions("user", "password", "domain.xyz")
{
IsPersistence = false,
Arguments = new []{ "rw" }
};
using (var cifsClient = new CifsMountClient(options))
using (var cifsMounted = cifsClient.Mount(shareDirectory, targetDirectory))
{
Console.WriteLine(cifsMounted.Directory.Exists);
// Do something with 'cifsMounted.Directory' like the plain DirectoryInfo type
}