pysmbclient /

Filename Size Date modified Message
35.1 KB
Initial release
2.7 KB
Small typo on the README
2.3 KB
Python 3 compatible release, thanks to Adrian Klaver who submitted the pull request.
17.4 KB
Python 3 compatibility.

== 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