Functions
sendfile(address, channel, source)
Sends a file to a remote device.
Raises lightblue.obex.OBEXError if an error occurred during the request, or
if the request was refused by the remote device.
Arguments:
- address: the address of the remote device
- channel: the RFCOMM channel of the remote OBEX service
- source: a filename or file-like object, containing the data to be
sent. If a file object is given, it must be opened for reading.
Note you can achieve the same thing using OBEXClient with something like
this:
>>> import lightblue
>>> client = lightblue.obex.OBEXClient(address, channel)
>>> client.connect()
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>> putresponse = client.put({"name": "MyFile.txt"}, file("MyFile.txt", 'rb'))
>>> client.disconnect()
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>> if putresponse.code != lightblue.obex.OK:
... raise lightblue.obex.OBEXError("request denied")
>>>
recvfile(sock, dest)
Receives a file through an OBEX service.
Arguments:
- sock: the server socket on which the file is to be received. Note
this socket must *not* be listening. Also, an OBEX service should
have been advertised on this socket.
- dest: a filename or file-like object, to which the received data will
be written. If a filename is given, any existing file will be
overwritten. If a file object is given, it must be opened for writing.
For example, to receive a file and save it as "MyFile.txt":
>>> from lightblue import *
>>> s = socket()
>>> s.bind(("", 0))
>>> advertise("My OBEX Service", s, OBEX)
>>> obex.recvfile(s, "MyFile.txt")