【发布时间】:2015-07-16 10:52:33
【问题描述】:
我正在使用 mac 机器。我可以访问 Windows 共享网络。我可以使用“smb://location”从我的 Mac 连接到它。
使用 python,我希望能够使用我的访问凭据在 Windows 共享网络上下载/上传文件。我该怎么做。
共享位置看起来像smb://v1/abc。我能够连接到这个。现在我想在这个连接的文件夹中创建一个文件。
我想在文件夹d2 中创建一个文件。我尝试使用pysmb 模块。我尝试了以下方法:
>>> fp = open('local_file.txt', 'w')
>>> conn = SMBConnection('user', 'password', 'test_v1','v1', use_ntlm_v2 = True)
>>> conn.retrieveFile('share', 'abc/d2/check.csv', fp)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/8417/repos/workspace/venv/lib/python2.7/site-packages/smb/SMBConnection.py", line 267, in retrieveFile
return self.retrieveFileFromOffset(service_name, path, file_obj, 0L, -1L, timeout)
File "/Users/8417/repos/workspace/venv/lib/python2.7/site-packages/smb/SMBConnection.py", line 283, in retrieveFileFromOffset
raise NotConnectedError('Not connected to server')
smb.base.NotConnectedError: Not connected to server
也试过了:
>>> conn = SMBConnection('user', 'password', 'test_v1','v1/abc', use_ntlm_v2 = True)
>>> conn.retrieveFile('share', 'd2/check.csv', fp)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/8417/repos/workspace/venv/lib/python2.7/site-packages/smb/SMBConnection.py", line 267, in retrieveFile
return self.retrieveFileFromOffset(service_name, path, file_obj, 0L, -1L, timeout)
File "/Users/8417/repos/workspace/venv/lib/python2.7/site-packages/smb/SMBConnection.py", line 283, in retrieveFileFromOffset
raise NotConnectedError('Not connected to server')
smb.base.NotConnectedError: Not connected to server
【问题讨论】:
-
你不能把 'smb://location' 作为本地文件夹挂载到你的 mac 机器上,然后使用
shutil.copy2()来复制文件吗? -
@J.F.Sebastian 如何在本地安装它?如果我这样做,它会同步吗?
-
google: mount smb share mac