本文主要是介绍Linux访问Windows的共享目录,pysmb(参数remote_name定义),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
方案一
net use
此命令只在Windows下面可用。
方案二
sudo mount -t cifs -o username=administrator,password=password //remote_share_server_ip/share_dir ./data
这条命令必须使用root权限,对于不能使用root权限的应用无法实现。没有sudo会报错:
mount: only root can use "--options" option
方案三
Python包pysmb
def check_unc_source(self, unc_path, username, password):conn = SMBConnection(username, password, '', remote_name, is_direct_tcp=True)result = conn.connect('remote_share_server_ip', 445)with open("local_file", "wb") as local_file:conn.retrieveFile("share_dir", "file", local_file)
SMBConnection第4个参数,remote_name:
The NetBIOS machine name of the remote server.
On windows, you can find out the machine name by right-clicking on the “My Computer” and selecting “Properties”.
This parameter must be the same as what has been configured on the remote server, or else the connection will be rejected.
实际上可以填写Windows远程共享目录所在服务器的IP地址,即和conn.connect的第一个参数remote_share_server_ip相同,如果为空,会报错:
smb.smb_structs.OperationFailure: Failed to retrieve [file] on share_dir: Unable to connect to shared device
这篇关于Linux访问Windows的共享目录,pysmb(参数remote_name定义)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!