2 回答

TA貢獻(xiàn)1784條經(jīng)驗 獲得超2個贊
使用 pysmb (文檔):
from smb.SMBConnection import SMBConnection
remote_address = "172.16.0.10"
share_name = "public_pictures"
conn = SMBConnection(username, password, name, remote_name)
conn.connect(remote_address)
accessible = share_name in conn.listShares()

TA貢獻(xiàn)1829條經(jīng)驗 獲得超7個贊
處理 samba 的一種方法是使用pysmb. 如果是這樣,那么它會類似于以下內(nèi)容:
# we need to provide localhost name to samba
hostname = socket.gethostname()
local_host = (hostname.split('.')[0] if hostname
else "SMB{:d}".format(os.getpid()))
# make a connection
cn = SMBConnection(
<username>, <password>, local_host, <netbios_server_name>,
domain=<domain>, use_ntlm_v2=<use_ntlm_v2>,
is_direct_tcp=<self.is_direct_tcp>)
# connect
if not cn.connect(<remote_host>, <remote_port>):
raise IOError
# working connection ... to check if a directory exists, ask for its attrs
attrs = cn.getAttributes(<shared_folder_name>, <path>, timeout=30)
一些注意事項:
在你上面的例子中,
public_pictures
是shared folder
, whilepath
只是/
您需要知道您是否在端口
139
或445
(或自定義端口)上使用 SMB 。如果是后者,您通常希望通過is_direct_tcp=True
(盡管某些服務(wù)器仍會在 上提供 NetBIOS samba445
)如果您希望不需要用戶名或密碼,那么您可能希望
username="guest"
使用空密碼進(jìn)行連接。
添加回答
舉報