ToolsPack.Samba 3.1.0

dotnet add package ToolsPack.Samba --version 3.1.0
NuGet\Install-Package ToolsPack.Samba -Version 3.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ToolsPack.Samba" Version="3.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ToolsPack.Samba --version 3.1.0
#r "nuget: ToolsPack.Samba, 3.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ToolsPack.Samba as a Cake Addin
#addin nuget:?package=ToolsPack.Samba&version=3.1.0

// Install ToolsPack.Samba as a Cake Tool
#tool nuget:?package=ToolsPack.Samba&version=3.1.0

Samba connection

This library wrap the native Windows function to etablish a cifs connection (Samba 1.0) to a remote storage.

Once the connection is etablished you can use normal C# functions to access and manipulate files / folders on the remote storage as if they are on your local storage..

Mount the remote storage

CifsConnectionManager conn = CifsConnectionManagerFactory.GetOrCreate(new FileStorageSetting
{
    RemoteLocation = @"\\10.20.30.40\carte_identity",
    BaseLocation = @"mb",
    Login = "hduong",
    Password = "secret",
});
conn.Connect();

the CifsConnectionManagerFactory ensure that you will have only 1 instance of CifsConnectionManager per setting

Unmount the remote storage

conn.Disconnect();

Check if the connection is mounted

string err = conn.CheckConnectionAlive();
if (err != null)
{
    throw new Exception("Connection is dead: here is the result of CheckConnectionAlive: " + err);
}

Behind the scene the we attempt to read a file test.txt on the remote storage, or try to create it on the remote storage.

Sample usage

In this example we will try to access to the file \\10.20.30.40\carte_identity\mb\01\doc.pdf ⇒ please read the comment along the code samples

//maybe the connection is already etablised (on the machine by other app) so we will just return the content of the file
if (File.Exists(@"\\10.20.30.40\carte_identity\mb\01\doc.pdf"))
{
    return await File.ReadAllBytesAsync(@"\\10.20.30.40\carte_identity\mb\01\doc.pdf");
}

//we didn't entered the above "if" So maybe the connection is not etablished or the file really not exist on the remote disk

//we will try to etablised the connection first

FileStorageSetting setting = new FileStorageSetting
{
    RemoteLocation = @"\\10.20.30.40\carte_identity",
    BaseLocation = @"mb",
    Login = "hduong",
    Password = "secret",
};
//CifsConnectionManagerFactory give a unique instance of a CifsConnectionManager correspond to the setting
CifsConnectionManager conn = CifsConnectionManagerFactory.GetOrCreate(setting);

//try to connect to the RemoteLocation 3 times. In the end it will throw NetworkDiskException if failed
await conn.Connect();

//Here the Connect() function didn't throw the NetworkDiskException. It means that the connection was succesfully etablished

//whenever you want to check the connection status, you can always call the CheckConnectionAlive() function
string err = conn.CheckConnectionAlive();
if (err != null)
{
    //the existence of the RemoteLocation\test.txt is not detected and attempt to create this file is failed
    throw new Exception("Connection is dead: here is the result of CheckConnectionAlive: " + err);
}

//you can use BasePath to access to other files relative to this path. BasePath is just (RemoteLocation + BaseLocation)
var pathToFile = Path.Combine(setting.BasePath, @"01\doc.pdf"); //it will give "\\10.20.30.40\carte_identity\mb\01\doc.pdf"

//the connection to the remote disk is alive but the file doc.pdf might not exist on the remote disk for real
if (File.Exists(pathToFile))
{
    //return the content of the file
    return await File.ReadAllBytesAsync(pathToFile);
}
else
{
    throw new Exception("No problem with the connection But the file doc.pdf really does not exist on the remote server");
}

//you can also unmount the connection
conn.Disconnect();

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.0 147 2/8/2024
3.0.3 96 2/8/2024
3.0.2 75 2/8/2024
3.0.1 1,072 11/27/2022
3.0.0 1,406 7/5/2022
1.0.3 6,644 5/14/2020
1.0.2 441 4/13/2020
1.0.1 532 4/4/2020
1.0.0 450 2/19/2020