Projects |
| My implemented thoughts |
|
pysamba
Created at 29/11/2009 18:08:31
Index
- Introduction
- Download
- Install
- User Guide
- Implemented methods
- Example
Introduction
PySamba is a full wrapper based in the work of Tim Potter. In fact, PySamba is built as a Python C extension over the cli library provided with samba-3.0.24 and a Python module that hides the complexity of the lower layer (smb) providing high-level commands like Mkdir or DiskAvail. At now, PySamba provides a fully functional samba wrapper, allowing the developer to interface any samba-capable device much like python’s ftplib does.
PySamba has been written by Juan M. Casillas and released under GNU GPL public License.
You need a gcc compiler, a python running environment (tested with 2.4.3) and
the samba-3.0.24 sources. PySamba Has been developed under an UNIX environment
(HP-UX) and tested against native NT shares.
Simple & Easy
from pysamba import *
... and go. Server login is encapsulated in the constructor, so just
provide the require parameters, and start working with your favorite
smb share. PySamba is easy to use, and easy to install.
Download
PySamba current version is 1.0. This version is the first major release, and it’s fully functional. You can download it from here.
Installation
See the INSTALL file, but the installation process is the following:
- Get Samba-3.0.24 and uncompress it.
- copy py_smb.c and py_smb.h into samba-3.0.24/source/python replacing the existing files
- go to samba-3.0.24/source and issue a configure --with-python=python. Then make , make install, make python_ext, make install This will install python’s dynamic library.
- Import pysamba from the directory where pysamba is, or copy it to any place under the PYTHONPATH
- You’re ready
User Guide
Methods
The implemented methods in class pysamba.SMBManager are:
- __init__(self, host, res, user, passwd, domain)
- Connect(self)
- DiskAvail(self)
- List(self,dir)
- DirSize(self, dirn=None)
- GetDir(self, remote, local)
- PutDir(self, local, remote)
- GetFile(self,remote,local, createdirs=False)
- Chdir(self, dir)
- PutFile(self,local,remote)
- Pwd(self)
- Unlink(self, fname)
- Exists(self, fname)
- Mkdir(self, dirname, parent=False)
- Rmdir(self, dirname, force=False)
- PrettyList(self,dir=None)
__init__(self, host, res, user, passwd, domain)
Initializes the connection with the server host,
mapping the resource res, with user user identified
by passwd in domain domain
Connect(self)
Connects to the server (applies the data passed in __init__
DiskAvail
Shows the space available in the share, in bytes
List(self,dir)
Lists the directory dir Format is \\dir (windows style)
DirSize(self, dirn=None)
Calculates the disk space ocuppied by dirn, in bytes.
if dirn is None, DirSize calculates the
space for the current working directory (set with Chdir)
GetDir(self, remote, local)
Download the directory remote inside local.
(e.g. GetDir("\\share\\img", "/tmp/")
creates /tmp/img)
PutDir(self, local, remote)
Upload the directory local inside remote.
(e.g. PutDir("/tmp/img", "\\share")
creates \\share\\img)
GetFile(self,remote,local, createdirs=False)
Download the fileremote inside local.
(e.g. GetFile("\\share\\img.png", "/tmp/")
creates /tmp/img.png)
PutFile(self,local,remote)
Upload the file local inside remote.
(e.g. PutFile("/tmp/img.png", "\\share")
creates \\share\\img.png)
Chdir(self, dir)
Changes to directory dir
(e.g. Chdir("\\share\\images")
Pwd(self)
Prints the "current working directory" in the share
Unlink(self, fname)
Deletes file fname
Exists(self, fname)
Checks if fname exists.
Mkdir(self, dirname, parent=False)
Creates directory dirname. If parent is True,
all the intermediate directories are created, also
Rmdir(self, dirname, force=False)
Deletes directory dirname. If force is True,
Rmdir works like a rm -rf
PrettyList(self,dir=None)
Shows a pretty directory listing for dir or the current
working directory
Example
from pysamba import SMBManager
host="smbserver"
share="myshare"
user="myuser"
passwd="mysecret"
domain="MYDOMAIN"
svr = SMBManager(host,share,user,passwd,domain)
if not svr.Connect():
print "Can’t connect with server"
sys.exit(1)
print svr.DiskAvail()
print svr.DirSize("\\onedir")
svr.GetDir("\\onedir", "/tmp")
svr.Mkdir("\\backups\\src", True)
svr.PutDir("/usr/tmp/samba-3.0.24","\\backups\\src")
svr.Rmdir("\\crappydir",True)
svr.Chdir("\\onedir\\listmedir")
print svr.Pwd()
svr.PrettyList()
svr.GetFile("\\onedir\\remote.png","/tmp/local.png")
svr.PutFile("/tmp/local2.png","\\onedir\\remote2.png")
|
|
|
|
|
| Browse by Language |
|
You can browse the project database using the project's
main language (C,C++,python).
|
|
| Browse by Category |
|
You can browse the project database using our project's
categories (system administration, daemon, games, etc.).
|
|
| Search in Projects |
|
|
|
|
|