在我目前的情况下,我的 Linux 服务器上有一个 python 脚本,它可以处理远程 Windows 共享文件夹中的一些 pdf 文件。我目前正在使用 smbclient 与其建立连接,但我无法处理文件,可能我需要首先将所有文件传输到我的 Linux 服务器,因为所有文件的大小都可能非常大,这是不利的。在这种情况下我还能做什么,有没有办法创建一个管道,python 脚本将在其中运行并使用这些文件来给出结果。
代码如下:
from smb.SMBConnection import SMBConnection
userID = '---------'
password = '-------'
client_machine_name = '-----'
server_name = ' '
server_ip = '...'
domain_name = '-------'
conn=SMBConnection(userID,password, client_machine_name, server_name,
domain=domain_name, use_ntlm_v2=True,is_direct_tcp=True)
conn.connect(server_ip, 445)
shares = conn.listShares()
# storing file names in a list
dirlist = []
for share in shares:
if not share.isSpecial and share.name not in ['NETLOGON', 'SYSVOL']:
sharedfiles = conn.listPath(share.name, '/DMDA_2.0_Files/ProcessedBatchDocPdfs/12345678')
for sharedfile in sharedfiles:
print(sharedfile.filename)
dirlist.append(sharedfile.filename)
# retrieve or download file
path = 'DMDA_2.0_Files/ProcessedBatchDocPdfs/12345678/111111.pdf'
with open('abc.pdf','wb') as f:
conn.retrieveFile(share.name, path, f)