Сохраните файл на локальном сервере с помощью pysmb - PullRequest
0 голосов
/ 28 января 2019

Я пишу скрипт для синхронизации папки с общей папкой на локальной синологии 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

Я не могу, кажется,передать правильный тип файла объекта.Основная ошибка, которую я получаю, это

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.Из моего заключения я должен передать объект байта, не открывая его уже, потому что он пытается это сделать, но как я могу получить этот файл байта с диска?Есть идеи?

1 Ответ

0 голосов
/ 28 января 2019

Параметр path storeFile должен содержать путь и имя файла, который должен быть создан / перезаписан.Чтобы сделать функцию максимально гибкой, имя не берется из file_obj (файлоподобный объект может даже не иметь имени).

...