在 Ubuntu 中,我可以使用 pysmb 连接到 Windows 网络共享,然后列出所有可用共享并列出该共享根目录下的所有文件和文件夹,但不会再进一步。我需要访问共享路径中的 5 个文件夹级别的文件夹,以将文件复制到该位置,并且无法越过文件共享的根级别。
我尝试在路径之间使用正斜杠和反斜杠(单斜杠和双斜杠),并尝试以任何一种方式包含和排除尾随斜杠。我只尝试了 1 个级别,也尝试了每个级别。
from smb.SMBConnection import SMBConnection
userid = 'myid'
password = 'mypassword'
client = 'clientMachine'
remote = 'remoteMachine'
server_ip = '5.5.5.5'
conn = SMBConnection(userid, password, client, remote, domain='MYDOM',use_ntlmv2 = True)
assert conn.connect(server_ip, 139)
sharelist = conn.listShares()
for s in sharelist:
print(s.name)
filelist = conn.listPath('Shared','/')
for f in filelist:
print(f.filename)
conn.close()
Run Code Online (Sandbox Code Playgroud)
如果我在 listPath 调用中包含除 '/' 以外的任何其他路径,即使我正在尝试的路径列在打印语句中,也会找不到路径:
Traceback (most recent call last):
File "testsmb.py", line 14, in <module>
filelist = conn.listPath('Shared', '/Corp/') …Run Code Online (Sandbox Code Playgroud)