Open Windows shared folder through linux machine

谁说我不能喝 提交于 2019-12-05 11:19:39

Linux has a utiliy called smbmount, which can be found in package smbutils I believe.

This is a command line utility which mounts a Windows share to a directory on the local machine, optionally with username/password.

smbmount is I believe a utility which runs as root, so whether it's suitable for you I don't know. Maybe it can be used as user.

You could either mount the share by default on the Linux machine, thereby accessing the files on it as local files, or you could do the smbmount / smbumount from within the python script with exec or something like that.

mkdir WindowsShare # Do this only once
smbmount \\server\share /home/me/WindowsShare -ousername=...,password=...
ls /home/me/WindowsShare
smbumount /home/me/WindowsShare

Username and password can be written in a file for some security. Check the man page.

If you need something totally python have a look at pysmb. Terms to google for are python, smb, CIFS.

urllib does not understand the SMB protocol. You will need to use gio via pygobject in order to retrieve the file.

If the folder is shared, I think it should be mounted in ~/.gvfs. Perhaps you can simply use open on the path as you see it in ~/.gvfs.

You should look for the default file browser.

And then you can execute the process and pass in the folder you want as an argument (smb://machine1/folder/).

For example on windows you would do:

execl("explorer.exe", "D:")

Try to look for the path to your file browser (most of the time it's Nautilus).

So:

execl("/bin/nautilus", "smb://.../")

Some info on execl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!