Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

== Python smbclient wrapper. ==

This is a wrapper that works by running the "smbclient" subprocess and providing
an API similar to the one provided by python `os` module.

It is an ugly hack, but it is here for anyone that finds it useful.

The programmer before me was using a "bash" file with lots of smbclient calls, 
so I think my solution is at least better.

=== Usage example ===

>>> smb = smbclient.SambaClient(server="MYSERVER", share="MYSHARE", 
                                username='foo', password='bar', domain='baz')
>>> print smb.listdir("/")
[u'file1.txt', u'file2.txt']
>>> f ='/file1.txt')
>>> data =
>>> f.close()
>>> smb.rename(u'/file1.txt', u'/file1.old')

=== Documentation ===

==== Creating the object ====

import smbclient
smb = smbclient.SambaClient(server, share, username=None, password=None,
                            domain=None, resolve_order=None, port=None, ip=None,
                            terminal_code=None, buffer_size=None,
                            debug_level=None, config_file=None, logdir=None,
                            netbios_name=None, kerberos=False)

If you want to use kerberos authentication just use the argument 
{{{kerberos=True}}} and you don't need to pass username and password.

==== Supported methods of operation ====

chmod(path, *modes)
      Set/reset file modes
      Tested with: AHS
      smbc.chmod('/file.txt', '+H')
       Closes the connection, flushes and closes all open remote files.
      Fetches information about a volume
      Fetches information about a file
      Returns True if path exists in the remote host

      Returns True if path is a directory/folder

      Returns True if path is a regular file

      Lists a glob (example: "/files/somefile.*")
      returns a list of tuples in the format:
      [(filename, modes, size, date), ...]

      Lists a directory
      returns a list of tuples in the format:
      [(filename, modes, size, date), ...]

      Emulates os.listdir()

      Creates a new folder remotely

      Removes a remote empty folder

open(path, mode='r')
      Opens the file indicated by path and returns it as a file-like object

rename(old_name, new_name)

      Fetches the volume name

      Fetches the volume serial

unlink(path) or remove(path)
      Removes/deletes/unlinks a file
download(remote_path, local_path)
upload(local_path, remote_path) 
upload_update(local_path, remote_path)

netsend(destination, message)
      Sends a message, using netsend

Recent activity


Commits by meeuw were pushed to chronossc/pysmbclient

2a864d6 - use instead of cowardly reading one byte don't kill the process, the child won't get killed anyway

Commits by meeuw were pushed to chronossc/pysmbclient

b200538 - only kill smbclient when it is spawned, when write_data failure raise SambaClientError
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.