azraelrabbit / CifsMount

A Simple Way To Use Shared Windows Folders On Linux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CifsMount

Nuget downloads Nuget Tests CodeQL

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

Requirements

  1. Install cifs-utils dependency
    sudo apt -y install cifs-utils
  2. Disable the password verification prompt for 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"'
  3. Create a directory to mount. Grant write permissions
    sudo mkdir -p /mnt/my_mount
    sudo chown test:test -R /mnt/my_mount

Usage

  1. Create mount options and define folders
  2. Create CifsMountClient and Mount() target folder

Example

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
}

About

A Simple Way To Use Shared Windows Folders On Linux

License:MIT License


Languages

Language:C# 100.0%