CifsMount 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
- Install
cifs-utils
dependencysudo apt -y install cifs-utils
- Disable the password verification prompt for
mount
andumount
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"'
- Create a directory to mount. Grant write permissions
sudo mkdir -p /mnt/my_mount sudo chown test:test -R /mnt/my_mount
- Create mount options and define folders
- Create
CifsMountClient
andMount()
target folder
var 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
}