xoofx / zio

A cross-platform abstract/virtual filesystem framework with many built-ins filesystems for .NET
BSD 2-Clause "Simplified" License
817 stars 61 forks source link

Read/Write on a network folder #30

Open enrichz opened 6 years ago

enrichz commented 6 years ago

I would like to read and write on a folder placed on a shared storage using the SubFileSystem. Is this possible? I can't seem to find the way, I always get the exception: A path on Windows must start by /mnt/ followed by the drive letter. Also, I'd like to be compatible with both Windows and Linux.

This is the code I have:

UPath root = "\\\\myserver\\PublicFolder\\";
var fs = new PhysicalFileSystem();
if (!fs.DirectoryExists(root))
{
    fs.CreateDirectory(root);
}
var subfs = new SubFileSystem(fs, root);

Thanks

xoofx commented 6 years ago

It is indeed not possible.

Also, I'd like to be compatible with both Windows and Linux.

What do you mean? Afaik, Linux doesn't have an equivalent of that right?

guillaume86 commented 6 years ago

I would also be interested in this feature, maybe a "/smb/SERVER-> \\SERVER\" convention enabled in windows environments could do the job the same way you handle local drives with "/mnt/C -> C:\".

Thank you for this lib, it looks very useful and well written.

LimpingNinja commented 5 years ago

Just adding a comment - on Linux you would mount an SMB path for perusal or use an smbclient; on Windows you'd do the same with NET USE:

net use s: \\myserver\publicfolder

Then in Zio you would use:

UPath root = "/mnt/s/";

Essentially using the 'net use' is mounting the path as a subsystem and even works on local. @guillaume86 how would you envision this being cross-supported or is this a windows only feature side?

VaslD commented 4 years ago

Something like \\MyServer\PublicFolder (unescaped) is an UNC Path. In short, UNC Path is the Windows way to normalize different formats of file paths, e.g. C:\Windows\, \\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\Foo.txt, D:Folder1 (yes, there is no / or \) can all be converted to UNC Paths. (But they don't have to be.)

.NET built-in IO accepts UNC Paths and other valid but not portable path formats on Windows. UPath may need additional logic to support conversion between different special path formats.

guillaume86 commented 4 years ago

Maybe a /unc/ root path could handle that on windows platforms? Just translating itself to \\ when transformed into a native path similarly to what /mnt/ is doing for mounted drives.

@xoofx any remarks/recommendations if someone was to tackle that?

xoofx commented 4 years ago

The integration into PhysicalFileSystem doesn't match. A unc is like an http connection where you have the host and the path inside it. I would prefer a new UncFileSystem("\\\\myserver\\PublicFolder\\") is introduced even if it requires to move some parts of PhysicalFileSystem to a base class. Note also that it might require to disable the file watcher API for this one. I don't have time, nor any personal interest in this feature, but a PR is welcome.