Using pysmbc to read files over samba

后端 未结 5 2169
忘了有多久
忘了有多久 2020-12-30 13:12

I am using the python-smbc library on Ubuntu to access a samba share. I can access the directory structure fine, I am however not sure how to access actual files and their c

5条回答
  •  甜味超标
    2020-12-30 13:59

    If you've managed to get the directory structure then you have a working context. The key to actually accessing files is the undocumented flags argument of Context.open. (I haven't figured out what mode is for either but it doesn't seem necessary.)

    flags is how you tell pysmbc what type of access to the file you want. You do that by passing it an integer made by bitwise ORing (|) flags from the os module together. Specifically the flags you want or suffixed with os.O_ (see a list in the Python documentation here).

    For example, to write to a file you would set flags to os.O_WRONLY (equiavlent to using "w" as the mode parameter of the built in open function) and to append to a file that might already exist use os.O_WRONLY | os.O_APPEND | os.O_CREAT (equivalent to "a+").

    That call will then return a file object which you can use like any normal, local file.

提交回复
热议问题