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

Close
== 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 = smb.open('/file1.txt')
>>> data = f.read()
>>> 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')
  
close()
       Closes the connection, flushes and closes all open remote files.
  
diskinfo(self)
      Fetches information about a volume
  
info(path)
      Fetches information about a file
  
exists(path)
      Returns True if path exists in the remote host

isdir(path)
      Returns True if path is a directory/folder

isfile(path)
      Returns True if path is a regular file

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

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

listdir(path)
      Emulates os.listdir()

mkdir(path)
      Creates a new folder remotely

rmdir(path)
      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)

volume()
      Fetches the volume name

serial()
      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

meeuw

Commits by meeuw were pushed to chronossc/pysmbclient

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

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 ProjectModifiedEvent.java.
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.