A Software Technologist's Blog (Wanna Email Me?)


June 9, 2009 By miketeo

pysmb is an experimental SMB/CIFS library written in Python. It implements the client-side SMB/CIFS protocol (SMB1 and SMB2) which allows your Python application to access and transfer files to/from SMB/CIFS shared folders like your Windows file sharing and Samba folders.

If you use pysmb in your applications, please drop me a comment at the bottom of this page to let me and the others know of what you have done using pysmb. Thanks.
For bug reports, please access the issue tracker on github.
For the latest code under development or if you wish to help out with pysmb development, please visit the pysmb repository on github.

What It Can Do

From version 1.0.0, pysmb has been completely rewritten and has been tested to be able to login to and upload/download files from shared folders on Samba, Windows XP, Windows Vista and Windows 7 machines. For more information on how to write your own file transfer applications using pysmb, please refer to the online documentation at readthedocs.org or check out the documentation in the 1.0 source files.

What It Can’t Do

Note that this is only a client library. It does not share files.


If you have problems opening tar.gz files in Windows, please install 7-Zip. It supports 7z, ZIP, GZIP, BZIP2, TAR and many other archive formats.

Version 1.1.28, 2019-11-23 (Download)

  • SharedFile instances returned from the listPath() method now has a new file_id attribute which represents the file reference number given by the SMB server. Contributed by electricbrew (github)

Version 1.1.27, 2019-01-09 (Download)

  • Remove support for SMB-2.1 dialect which could be causing compatibility issues with Windows 2008 R2.

Version 1.1.26, 2019-01-05 (Download)

  • Prevents OperationError from being raised when listPath() operation does not return any matching file results.
  • SMBConnection is now a context manager

Version 1.1.25, 2018-07-28 (Download)

  • Fix buggy support for search parameter in listPath() method. Add SMB_FILE_ATTRIBUTE_INCL_NORMAL bit constant to include ‘normal’ files with other file types in the returned result. From now on, pysmb defines a ‘normal’ file as a file entry that is not read-only, not hidden, not system, not archive and not a directory; it ignores other attributes like compression, indexed, sparse, temporary and encryption. listPath() method will now include ‘normal’ files using the default search parameter.
  • Add isNormal property to SharedFile class to support test if the file is a ‘normal’ file (according to pysmb definition of ‘normal’ file).

Version 1.1.24, 2018-07-19 (Download)

  • Improve listPath implementation for SMB1
  • Support for STATUS_PENDING responses across all SMB2 operations.

Version 1.1.23, 2018-05-05 (Download)

  • Fix bug in listShares() method which fails when the remote server has many shares. Contributed by carlosefr (github).
  • Improve echo() method to test and fail if the provided data to echo is not a bytes object. Contributed by carlosefr (github).
  • Fix bug in listPath() method where the path to query is not properly terminated. Contributed by Yepoleb (github).

Version 1.1.22, 2017-09-17 (Download)

  • Fix bug in getAttributes() method which should return only the filename instead of the entire path for the filename property for the return result.

Version 1.1.21, 2017-09-09 (Download)

  • Fix bug where timestamp values for SMB1 getAttributes() response are not converted properly from FILETIME to epoch time values.

Version 1.1.20, 2017-08-13 (Download)

  • Add getSecurity() method to support security descriptors query via SMB2. Contributed by koniiiik (github).
  • Improve retrieveFile() and retrieveFileFromOffset() methods to allow file retrievals over SMB2 even when the file is being locked on the server.
  • Silently discards NMB SESSION_KEEPALIVE packets instead of raising warnings. Thanks to a-mushroom (github) for reporting this.
  • SMB sessionID will be sent in ECHO requests to conform to SMB2 specs. Thanks to divad (github) for reporting this.
  • Fix type errors for MD4 functions in python3. Contributed by viatoriche (github).

Version 1.1.19, 2016-11-13 (Download)

  • Ignore STATUS_PENDING during delete and file store operations

Version 1.1.18, 2016-04-09 (Download)

  • Rollback fixes to NTLMv2 response algorithm in pysmb 1.1.17. The fixes fail to work with some servers.
  • Add missing errno imports in SMBConnection.py
  • Fix UnboundLocalError raised when using type() in SMBConnection.py

Version 1.1.17, 2015-11-11 (Download)

  • Fix crashes in directory listing with keyerror ‘support_dfs’.
  • Fix bugs in NTLMv2 response algorithm.
  • Fix bugs where client domain is not included as part of the session negotiation.

Version 1.1.16, 2015-05-10 (Download)

  • Fix typo errors in authentication error messages.
  • Improve share listings on SMB2 protocol by ignoring interim STATUS_PENDING responses.

Version 1.1.15, 2015-02-15 (Download)

  • Add new parameter to SMBConnection’s storeFileFromOffset method to determine whether the remote file is to be truncated before writing.

Version 1.1.14, 2015-02-01 (Download)

  • Add support for DFS shares in listPath(). Thanks to humberry (github) for raising the issue and helping with the testing.
  • Fix bug in python3’s SMB2 listPath implementation. Thanks to deejrose (github) for reporting the bug.

Version 1.1.13, 2014-10-18 (Download)

  • Add missing methods and improve compatibility with python3. Thanks to keisetsu (github) for submitting the patch.
  • Fix bug in SMB2 rename implementation which fails to rename directory. Thanks to Jayke Meijer for raising the bug and providing the packet capture.

Version 1.1.12, 2014-09-21 (Download)

  • Fix syntax error for python3 NBNSProtocol implementation
  • Fix bug in SMB1 implementation which results in access denied errors with Samba 3.0. Many thanks for John Sivak for his assistance and support in helping to troubleshoot and test the bug fixes.

Version 1.1.11, 2014-09-13 (Download)

  • Add support for unicode characters in domain, username and password.
  • Add storeFileFromOffset method to SMB API
  • Fix bug in getAttributes implementation for SMB1
  • Fix bug for NMB which uses broadcast flag for unicast queries
  • Update the Tree Connect Andx request implementation to support MS-SMB extensions

Version 1.1.10, 2014-06-29 (Download)

  •  Add getAttributes() method to SMBConnection and SMBProtocolFactory class.
  • Add isReadOnly property to SharedFile class.

Version 1.1.9, 2014-06-01 (Download)

  • Add support for domains in smb:// URLs. Contributed by Andy Piper.
  • Fix a bug which fails to test for the correct GSS security provider OID values. Thanks for Fanen for bug report and assistance in testing the fix.

Version 1.1.8, 2013-12-21 (Download)

  • Fix a bug in storeFile() method when the destination file is not overwritten if it exists in SMB1 communication. Thanks to Vaikar Amol for reporting this bug and helping to fix it.
  • Fix a SMB1 authentication problem when extended negotation is not carried out because the remote server has specified its support for extended security in the payload, instead of in the message flags2.

Version 1.1.7, 2013-09-27 (Download)

  • Improve listShares() function which can fail with the listing response is separated into multiple SMB packets for large number of shares. Thanks to Pieter De Clerck for reporting this bug and helping to test the bug fix.
  • Fix bug in python3 implementation where session connection can fail when remote server supports message signing. Thanks to Simon for reporting this bug.

Version 1.1.6, 2013-08-16 (Download)

  • Fix bug where the status of the SMB_COM_NEGOTIATE reply is not checked for error before allowing further processing. Thanks to Adrian Cox for discovering this bug and submitting the patch.

Version 1.1.5, 2013-06-19 (Download)

  • Add support for Direct hosting of SMB over TCP/IP (TCP port 445)

Version 1.1.4, 2013-05-31 (Download)

  • Improve query performance for query IP addresses for NetBIOS names in NetBIOSProtocol.py. Thanks to Ties de Kock for submitting the performance patch.
  • Fix bugs in SMBConnection when sending large data packets can result in AssertionError. Thanks to David K. Hess for submitting the bug fix.

Version 1.1.3, 2013-03-18 (Download)

  • Fix a bug which results in endless loop in SMBConnection when remote CIFS server closes the connection. Thanks to Nitin Garg for submitting the bug fixes.

Version 1.1.2, 2012-09-28 (Download)

  • Improve queryIPForName() in nmb.NetBIOS and nmb.NBNSProtocol class to return only server machine name and ignore workgroup names.

Version 1.1.1, 2012-06-09 (Download)

  • Adds support for Python3. Noted that the Python3 SMB/NMB protocol implementations for Twisted are not well-tested as Twisted (as of v12.1) is not Python3 ready yet.
  • Adds support for retrieving list of shadow copies (also known as “previous versions” in Windows). Note that not all Windows editions support shadow copies.

Version 1.1.0, 2012-06-01 (Download)

  • Adds SMB2 protocol implementation with signing for outgoing SMB2 messages. pysmb will utilize SMB2 protocol with servers that support SMB2 protocol (eg. Windows Vista, Windows 7 and Samba 3).  If the remote server does not support SMB2, pysmb will fall back automatically to using SMB1 protocol.

Version 1.0.5, 2012-05-07 (Download)

  • Add supports for SMB message signing. pysmb can sign SMB messages from the CIFS client to the server, but it does not verify the signatures of the  SMB messages from the server.

Version 1.0.4, 2012-05-01 (Download)

  • Adds support for “smb://” URL in urllib2 python packages to retrieve or upload files from/to remote CIFS servers.
  • Improve documentation

Version 1.0.3, 2012-04-28 (Download)

  • Fix a crash in SMB._storFile() method which occurs when the remote CIFS server utilizes a max raw size larger than 65535 bytes. The bug was discovered with  Windows 7 Pro SP1. Thanks to Bram Deprettere for submitting the bug report.
  • Fix a bug in SMB._listPath() method where the files/folders time information are not properly converted to Epoch time. Thanks to John Lau for discovering this bug.
  • Add NBNSProtocol.queryIPForName() and NetBIOS.queryIPForName() methods to query for a machine’s NetBIOS name at the given IP address. Thanks to Jason Anderson for providing the initial implementation.
  • Add SMBProtocol.retrieveFileFromOffset() and SMBConnection.retrieveFileFromOffset() methods for a finer control of file retrieval operation with read offset and write limits.

Version 1.0.2, 2012-03-25 (Download)

  • Fix a bug in SMB._handleSessionChallenge() method in base.py where the domain attribute was not used to generate the corresponding NTLM authentication packets, resulting in the default WORKGROUP domain for used for all subsequent authentications. Thanks to John Lau for submitting the bug report.

Version 1.0.1, 2012-01-25 (Download)

  • Fixes a bug in listPath() method which causes directory listing for sub-directories to return an empty list.
  • Fixes an incorrect implementation of the TRANS2_FIND_FIRST2 and TRANS2_FIND_NEXT2 request/response handling which causes directory listing to crash when the remote directory contains a certain number of entries.

Version 1.0.0a, 2011-12-30 (Download)

  • Completely rewrites pysmb. API is not compatible with previous pysmb-0.x.x
  • Supports NTLMv1 and NTLMv2 authentication
  • Adds in NMB/SMB protocol implementation for use with Twisted framework
  • Tested with Windows XP SP3, Windows Vista, Windows 7 and Samba 3.x
  • Requires Python 2.4.4 or later, and pyasn1. Not tested with Python3
  • Fixes a bug in previous release (1.0.0) where the package was not built properly and had missing files. (Many thanks to Adrian Klaver for pointing this out)

Version 0.4.5, 2009-06-22 (Download)

  • Prevents pysmb from failing when there are too many files/folders to
    be returned in a single SMB TRANS2 call. pysmb will “resume” requesting
    for more files/folders information in subsequent SMB TRANS2 requests.

Version 0.4.4, 2004-01-12 (Download)

  • Add in support for AMK’s Python Cryptography Toolkit which will be used for DES password hashing. If AMK’s pycrypto is found, it will be used instead of mxCrypto.

Version 0.4.3, 2003-02-22 (Download)

  • Fix a bug which fails to close the socket in nmb.py on socket exception
  • Fix a bug which fails to close the NetBIOSSession in smb.py if the session has not been properly established yet

Version 0.4.2, 2002-08-03 (Download)

  • Add new methods to SharedFile instances, get_mtime_epoch, get_atime_epoch and get_ctime_epoch. These methods will return the mtime, atime and ctime in epoch time rather than SMB time.
  • Remove debugging printout in smb.py which has been released accidentally with the last release.
  • Fix a bug in smbcp which causes to local to remote copy to fail

Version 0.4.1, 2002-06-22 (Download)

  • Fix a bug in smb.py which does not return the correct file size for files with their archive bits turned off. This results in these files not being retrieved or sent properly.
  • Fix some typo error in the documentations

Version 0.4.0, 2002-04-17 (Download)

  • Use NT LM0.12 dialect.
  • New smb.SMBMachine class
  • Add SMB.get_server_domain(), smb.get_server_os(), SMB.get_server_lanman()

Version 0.3.1, 2001-11-12 (Download)

  • Fix a problem with some Windows server where an UID is required when server is in share mode.  Now, pysmb calls login() with empty authentication information when server is in share mode.
  • Add TYPE_DOMAIN_MASTER constant and description to nmb.py.

Version 0.3.0, 2001-11-10 (Download)

  • Add support for services in share mode. Minor changes to smb.SMB class API.
  • Fix a bug in smb.py’s __raw_retr_file which has failed to initialize the max_buf_size prior to usage.
  • Fix a bug in smblistshare which fails to print the correct NMB error message
  • Modify smb.py not throw AttributeError in the destructor when there is an error while creating a session in the constructor

Version 0.2.0, 2001-10-04 (Download)

  • Add support for encrypted authentication using DES
  • Fix a bug(?) which treats all services and filenames as case-sensitive

Version 0.1.3, 2001-09-03 (Download)

  • Fix a bug in smblistshare and smbdu which fails to catch the nmb.NetBIOSError raised when session setup fails.
  • Fix a bug in smb.SMB that arises from the change in nmb.NetBIOSSession which sends the session port number as the remote host type.
Version 0.1.2, 2001-09-01 (Download)
  • Fix a bug in nmb.NetBIOSSession which specifies a TYPE_WORKSTATION for remote host instead of TYPE_SERVER.
  • Minor change to nmb.NetBIOSSession constructor API.
  • Fix a bug in smbdu which raises OverflowError when printing long file size values.
  • Fix a bug in smbcp which does not handle the destination path correctly when the source file is copied to a different filename.
Version 0.1.1, 2001-08-25 (Download)
  • Change nmb’s NetBIOS and NetBIOSSession class such that they raise a NetBIOSError with a tuple of ( err_msg, err_class, err_code )
  • Add a function strerror() in both smb and nmb to return human readable messages for error codes.
  • Fix a bug in smbcp which fails to print an error message and terminate when the remote source path is not found.
  • Add in another utility, smblistshare.
Version 0.1.0, 2001-08-20 (Download)
  • First public release
  1. MikeTeo.net » Blog Archive » pysmb 0.4.5 released! Said,

    […] more information, please visit: http://miketeo.net/wp/index.php/projects/pysmb Bookmark This Rattle… Posted in: Python, Software Development ADD […]

  2. Thorsten Kaufmann Said,

    Hi Mike,

    great piece of code and seems to work pretty flawlessly. Just one minor thing i would love to do is reuse an existing connection to a smb server. So on windows once you are logged in on a server with say explorer it wouldnt re-need authentication and would reuse the windows connection. Is that possible and how would i go about it ?

    Kind Regards and thanks in advance,

  3. Stef Bon Said,


    I’m looking for an example to lookup the hosts in my network. Where can I find it?


  4. miketeo Said,

    @Stef Bon:
    You can try the following code with pysmb-1.0.4 and above. You may need administrator privilege to run the queryName() method.

    from nmb.NetBIOS import NetBIOS

    n = NetBIOS()
    print n.queryName('CETUS')
    print n.queryIPForName('')

  5. Ramakrishna Said,

    Hi Mike,

    Found this tool interesting. Thanks for developing and supporting this great work.

    We work on the SMB Protocol optimization and looking for an open source test tool for unit testing purposes during development.

    Can we use this tool to write customized smb protocol test scripts.

    Looking forward to hear your inputs.

  6. miketeo Said,

    @Ramakrishna: Yes, you can.

  7. Nitin Said,

    Hi Mike!
    Thanks for the awesome module. I have a couple of doubts though:

    1. Once a connection is made (using SMBConnection and connect method), how long does the connection last?
    2. How are the read/write calls to the CIFS server authenticated? Through a sesssion or are username and password passed along every time?


  8. miketeo Said,

    1. In development, most servers drop the connection after being idle for about 5 minutes. As documented, you should not keep the SMBConnection “idle” if you are not using it.
    2. The authentication is performed once during session setup during which the user name and password are transmitted in a secure manner. The authentication is not performed during file operations.

  9. Nitin Said,

    Thanks for the prompt reply! Follow up questions 🙂

    So when the connection is made, does the server pass some kind of session token or session ID to the client? And then the client passes that token during file operations? If so, where is this ID/token stored?

    OR the server creates a session and keeps the information to itself and validates incoming requests based on IP address? And upon 5 minutes of inactivity, destroys the session?

  10. miketeo Said,

    @Nitin: When the connection is established, the SMB client and server engage in a session negotiation phase which determines the variant of SMB protocol (aka SMB dialect) and also involves authenticating the remote SMB client. The session information is only useful within the authentication communication and is not being used directly in subsequent file operations. When the TCP connection is closed, the remote SMB client will need to perform the session negotiation and authentication again when it re-connects back to the server.

  11. Nitin Said,

    Thanks again. And lastly I want to ask: Is there any support to connect using Active Directory’s UPNs (User Principal Names) like username@domain? I tried putting the username and domain parameters in the constructor, but it didn’t work.

    SMBConnection(username, password, my_name, remote_name, domain=”, use_ntlm_v2=True, sign_options=2)

    Actually I tried UPN with the smbclient command too, but that didn’t work either. So SMB doesn’t allow connections using UPNs?

  12. miketeo Said,

    I have heard that one of the pysmb users had used pysmb to authenticate against AD successfully.

  13. Nitin Said,

    Someone posted this in Nov last year, and I’m facing the same issue now: http://stackoverflow.com/questions/13252443/pysmb-windows-file-share-buffer-overflow

    Interestingly it happens only after I create a new share on the server.
    FYI: Client is a CentOS 5 machine and the server is a Win 2008 R2.

  14. miketeo Said,

    @Nitin: Can you send me the tcpdump of the communication using ethereal?

  15. Nitin Said,

    Hey Mike, sorry about the late reply. I’m not using listShares anymore, but I’ll send you the tcpdump soon if possible.

    Meanwhile, is there any way that listPath can return the list in batches. E.g. a folder has 1 million files, and I want the server to return the list in batches of 100. Because returning all the 1 million items together takes up too much time. I don’t see any such options for listPath in the documentation, but is it possible to play with the underlying code to make this possible?

  16. miketeo Said,

    The SMBConnection class does not support asynchronous operations. You might want to look into the SMBProtocolFactory (which uses Twisted framework) and subclass the listPath method implementation in the SMBProtocol to incorporate your batched retrieval needs.

  17. Nitin Said,

    Hi Mike,

    Does pysmb support SMB communications directly over TCP, port 445?

    If not, is there any way to get pysmb working with a server that doesn’t support NetBIOS?

  18. miketeo Said,

    @Nitin: As of pysmb 1.1.3, pysmb does not support direct SMB over TCP. There are some modifications required to bypass the NetBIOS session setup and add in some shim NetBIOS session headers for this to work.

  19. Guy Said,

    Thanks for developing pysmb! I integrated it into a library I’m using with Robot Framework to help test a NAS product. It works very well for verifying permissions. Unfortunately I’m unable to use pysmb for performance testing, since it seems to top out at around 15 MB/s on my test PCs when used with this NAS. Still, it’s a very very useful library.

    I did notice a typo in one of the debug messages – ‘authentication’ is misspelled. See: Authetication with remote machine “” for user “guest” will be using NTLM v2 authentication (with extended security)

  20. Guy Said,

    I retract my earlier statement about performance. The poor performance was due to an error on my part.

  21. Sascha Gottfried Said,

    Hi Mike,
    I used version 1.1.5 today to connect to DFS shares. With direct hosting of SMB via port 445 enabled, I got a connection opened and listed several shared devices. But listing subdirectories or opening files always resulted in the following error (resource names changed) :

    OperationFailure: Failed to list \directoryname\filename on device: Unable to open directory

    Where do you host the project, how can I run the test suite to get results targetting my DFS environment, where is the issue tracker???

  22. miketeo Said,

    @Sascha: Are you able to try connecting to NetBIOS over TCP (port 139)?

    I use python nose for regression testing. To repeat the regression tests, simply unzip the contents of pysmb/tests/smbtest.zip into a shared folder named smbtest. Then modify pysmb/tests/connection.ini to match your SMB/CIFS server’s IP address. Finally, run “nosetest” in the pysmb/tests folder to begin testing.

    Unfortunately, there is no issue tracker for pysmb. The bug reports come to me directly via email.

  23. Pieter Said,


    We are using pysmb and we are very happy about it.

    We however encountered an issue when using it to listshares against a windows 2012 fileserer hosting more than 1500 share from a ubuntu machine.

    tcpdump shows following error:
    IOCTL Respone, Error: STATUS_BUFFER_OVERFLOW[Malformed Packet]

    It seems the buffer of pysmb is nog big enough.

    Is this a known issue?

    With kind regards,


  24. miketeo Said,

    @Pieter: I have to admit that pysmb has not been tested against that many number of shares. I can run some tests over the weekend to see if I can uncover any issues. If possible, can you send me a packet dump of the TCP communication to speed up the troubleshooting process?

  25. Basic Said,

    Hi Mike,

    I’m having a problem with connecting to a Windows Server 2008 share. (Full details here: http://stackoverflow.com/questions/18762564/unable-to-connect-to-windows-shares/18762998?noredirect=1#comment27660942_18762998 )

    I’ve found that in Python 3.3, the following line:

    self.signing_session_key = (session_key + ”*16)[:16]

    Fails (can’t concat byte array and string). Changing it to:

    self.signing_session_key = (session_key + (”*16).encode(‘utf-8’))[:16]

    allows it to connect. I still get a “smb.smb_structs.OperationFailure: Failed to list shares: Unable to retrieve shared device list” when trying to list shares but that’s a different problem.

  26. David Said,


    Using your library as a simple python utility to remotely touch web.configs to restart app pools, also thinking about incorporating it into a tool to rapidly find misconfigurations in some of our environments.

    Great little tool!


  27. nucco Said,

    Hi, do you know why connections fail with STATUS_MORE_PROCESSING_REQUIRED ?

  28. nucco Said,

    I’m not sure if I am allowed to share the captures, it seems like pysmb is unable to handle the netbios attributes list returned by the server. Server Returns “NetBIOS computer name” and “NetBIOS domain name”

  29. miketeo Said,

    @nucco: STATUS_MORE_PROCESSING_REQUIRED are returned from servers supporting GSS authentication tokens. pysmb should handle this transparently when you provide the correct user name and password.

  30. miketeo Said,

    @nucco: It will be best to share the packet captures. Otherwise, it will be difficult to give you any helpful pointers.

  31. Jayke Said,

    Hi Mike,

    I am using pysmb and it works perfect for almost everything I’m trying to do. However, I am having some issues with the “rename” option. I get the following error:
    Failed to rename music\test on media: Unable to open file/directory

    If I replace the rename with a delete and subsequent create command it does work, so it seems not to be a permission and/or filename issue.

    Do you have a clue what could be wrong? Thanks in advance!


  32. miketeo Said,

    @Jayke: Since other pysmb functions have been working for you, I’m guessing you have been using pysmb correctly. Can you provide me with the OS version and/or Samba version of the remote server? It will be ideal if you can provide me with the packet capture from wireshark of the failed rename communication as well.

  33. Jayke Said,

    Thanks for responding so quickly. Both the machine running the code and the machine I’m using as samba share are freshly installed Ubuntu 14.04 VM’s. The samba version on the share machine is Version 4.1.6-Ubuntu. It’s using the SMB2 protocol.

    The code I’m using is the following:
    print share, path, new_path
    conn.rename(share, path, new_path)

    That print statement gives this output:
    media music/test music/test2

    As said yesterday, if I replace the conn.rename with a delete and create statement for path and new_path respectively it succeeds. By the way, this is the case for both files and folders.

    I’m mailing you the packet capture!

  34. Mark Said,

    Hi Mike,

    I am able to connect to a certain machine via Direct TCP and using SMB2 only. NETBIOS and SMB1 appear not to work for me.

    When I test this setup from my development machine, it authenticates and establishes a connection fine.

    When I roll out the script on to our production platform, I cannot authenticate with the following error message.

    smb.smb_structs.ProtocolError: Security provider “(1, 3, 6, 1, 4, 1, 311, 2, 2, 10)” is not supported by pysmb

    Any ideas?


  35. miketeo Said,

    @Mark: What is the OS for the remote server on your production platform?

  36. Mark Said,

    Production is Ubuntu server, dev is Mint

  37. miketeo Said,

    @Mark: which release of Ubuntu? And the version of Samba? pysmb is developed on Ubuntu 14.04.

  38. Mark Said,

    I will check, I saw that its not up to date, but cannot recall what version its on. Is the security provider an OS specific library?

  39. Mark Said,

    Production is Ubuntu 12.04 LTS, running Samba 3.6.3
    Development is Mint 17.1, running Samba 4.1.6

    I will try and upgrade when we can, and let you know if that helps. Thanks.

  40. Mark Said,

    He have resolved this issue by upgrading pyasn from 0.0.11a to 0.1.7. Thanks.

  41. David Said,

    Hi Miketeo, is there a way to read only first several bytes from the remote file and do some changes on the bytes, then write the changed bytes back to the same file?

  42. miketeo Said,

    @David: Try the retrieveFileFromOffset() method and storeFileFromOffset() method in SMBConnection class.

  43. David Said,

    Thank you Miketeo, but it seems that storeFileFromOffset will wipe out the original content and then re-write. For example, the original content of write.txt is ‘aaaaaa’,
    when execute:
    temp_fh = BytesIO(‘xxx’.encode(‘UTF-8’))
    filesize = conn.storeFileFromOffset(‘smb’, ‘/write.txt’, temp_fh, offset = 0)
    The content of file write.txt become ‘xxx’, can it be ‘xxxaaa’?

  44. miketeo Said,

    @David: Current pysmb implementation 1.1.14 does not support this yet. I can do another release over the weekend with an API that allows you not to truncate the file.

  45. David Said,

    Thank you Miketeo

  46. iNoob Said,


    Firstly Great library!, I have some questions around the SMBconnect methods. The connect method you supply a Domain value but this value is just ignored. Closer look at the SMBConnection.py shows you are assigning domain = ” in the def__init___. Is there any reason your doing this? Another Question, the OS field in the connect always shows a value of pysmb. Capturing the SMB packets via wireshark shows the value in the setup andx request. I cant seem to find were you have specific this value?

  47. miketeo Said,

    @iNoob: The domain parameter is used in the generation of security payload during authentication. The OS value is hardcoded in ComSessionSetupAndxRequest__NoSecurityExtension’s prepare() method in smb_structs.py

  48. Chris Said,

    Hi Mike – thanks for the library – great stuff!

    One thing to consider for a future enhancement is the ability to update and or specify the file attributes when using the storeFile method or have it available as a secondary operation. It would be useful to reset the file attributes, create time, last mod and last access times to their original state as an option. This would be ideal if you were for example copying an existing file and wanted to retain the original values versus simply creating a new file with new attributes and properties.

  49. miketeo Said,

    @Chris: Thank you for your suggestion. I will keep this in mind when I start work on the next round of enhancements.

  50. Peter Simm Said,

    Hi Mike,

    Great project! Is there any scope for interrogating permissions on CIFS/SMB shares in a similar way to how smbcacls lets you do it in Linux?

Add A Comment