Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang: Access a Windows share (from Linux application)

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?

like image 627
Bart Silverstrim Avatar asked Jun 09 '14 16:06

Bart Silverstrim


People also ask

Can I access a Windows share from Linux?

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.

How do I access a file server in Linux?

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.

How mount Windows network drive in Linux?

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.


1 Answers

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.

like image 187
johannes Avatar answered Nov 15 '22 08:11

johannes