Is there a proper way to connect to a Windows share, such as \windowspc\c$\myshare, from a Go application that is compiled and running on a Linux device?
The share will require credentials to save a file to the target UNC path.
Is there a best practices to accomplish this?
Access a Windows shared folder from Linux using Nautilus Open Nautilus. From the File menu, select Connect to Server. In the Service type drop-down box, select Windows share. In the Server field, enter the name of your computer.
Connect to a file server In the file manager, click Other Locations in the sidebar. In Connect to Server, enter the address of the server, in the form of a URL. Details on supported URLs are listed below. If you have connected to the server before, you can click on it in the Recent Servers list.
Install CIFS-utils The safest way to mount Windows-shared folders on Linux is to use the CIFS-utils package and mount the folder using the Linux terminal. This allows Linux machines to access SMB file shares used by Windows PCs. Once installed, you can then mount your Windows share folder from the Linux terminal.
Theoretically yes, practically no.
Windows shares use the SMB/CIFS family of protocols. Those can be implemented in Go and be used to access the shares. This is a huge task, though.
Instead of having this in your application the best way is to require the share to be mounted from your system and then access it like a local file system from the application.
If you really want to use SMB/CIFS you can check whether the Gnome VFS (virtual file system) or FUSE as C libraries from within Go, but this will be messy and ugly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With