首页 > 解决方案 > 在 Python 中使用 Samba 客户端将文件从 Linux 复制到 Windows

问题描述

我正在尝试将文件从 Linux 机器复制到 Windows 共享驱动器。此答案显示了如何使用 Samba 客户端执行此操作。在我的情况下,连接成功,listShares()返回服务器上的共享但是当我打电话时connection.storeFile()我得到Unable to connect to shared device. 我错过了什么?

Linux机器上运行的python代码:

connection = SMBConnection(username='user1', password='password1', my_name='host1',remote_name='fs01',domain='domain', use_ntlm_v2=True)
connection.connect(ip, 139) # Returns true
file_obj = open(filename,"r") 
connection.storeFile('\\\\fs01\\data\\folder1', file1, file_obj) 

smb.smb_structs.OperationFailure: Failed to store data\folder1\file1 on fs01: Unable to connect to shared device

标签: pythonlinuxwindowssamba

解决方案


推荐阅读