方案一
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
|