gpt4 book ai didi

python - 使用 pysmb 将文件存储到本地服务器

转载 作者:太空宇宙 更新时间:2023-11-04 04:21:44 30 4
gpt4 key购买 nike

我正在编写一个脚本来将文件夹与本地 synology nas 上的共享文件夹同步。我能够连接、读取文件和删除,没问题,但我卡在复制(storefile)上。

pysmb 的文档是这样的

storeFile(service_name, path, file_obj, timeout=30)
Store the contents of the file_obj at path on the service_name. If
the file already exists on the remote server, it will be truncated
and overwritten.

Parameters:
service_name (string/unicode) – the name of the shared folder for the
path
path (string/unicode) – Path of the file on the remote server. If the
file at path does not exist, it will be created. Otherwise, it will
be overwritten. If the path refers to a folder or the file cannot be
opened for writing, an OperationFailure will be raised.
file_obj – A file-like object that has a read method. Data will read
continuously from file_obj until EOF.

Returns:
Number of bytes uploaded

我似乎无法传递正确类型的文件 obj。我收到的主要错误是这个

smb.smb_structs.OperationFailure: Failed to store  on andrews-itunes: Unable to open file

这是我的尝试

    with open(start_path + f, 'rb', buffering=0) as file_obj:
conn.storeFile(server_path, '/', file_obj)
file_obj.closed

我也尝试过使用 io.BYTESIO。从我的结论来看,我必须在不打开字节对象的情况下传递它,因为它试图这样做,但是我怎么能从驱动器中获取该字节文件呢?有什么想法吗?

最佳答案

storeFilepath 参数必须包含应创建/覆盖的文件的路径和名称。为了使函数尽可能灵活,名称不是取自file_obj(类文件对象甚至可能没有名称)。

关于python - 使用 pysmb 将文件存储到本地服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54394266/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com