How to pull a file from remote device with obex
The purpose of this document is to show how we can use Obex protocol to pull a file from remote device over Bluetooth link by using Obex protocol. Normally in S60 devices, we see send via Bluetooth, this opposite to that, it is Pull via Bluetooth or something similar. You can't read all the files from remote devices. If you see the file from remote device you can use Obex Client Get method to get the file to local device and save it.
We need Obex level connection to remote device before getting the file. Once we have established the connection we need to call SetPath() method of Obex client.
First we need to connect to FTP service.
Header file contents
CObexBufObject is used to hold the body part of the file as CBufFlat. Obex header information can be passed as CObexHeader. CObexClient is the main class in this process and is used to initiate connection with remote device, change directory in remote device and get file from remote device.
// Header file
How to make a request
*Method: GetFileObjectL(), This method is used to get the file.
*param: aFileName, File name that we are trying to get
*Precondition: SetPath must be called before calling this method
void CMyBTBrowserObexClient::GetFileObjectL(TFileName& aFileName)
if ( iGetObject )
iGetObject = NULL;
if ( iObjectBuffer )
iObjectBuffer = NULL;
iObjectBuffer = CBufFlat::NewL( KBTSUDataBufferExpandSize );
iGetObject = CObexBufObject::NewL( iObjectBuffer );
const TUint8 KNameHeaderHi = 0x01;
CObexHeader* nameHeader = CObexHeader::NewL();
CleanupStack::Pop(nameHeader); // Ownership has been passed
iClientState = EBTSCliGettingFile; // state of my application
iClient->Get( *iGetObject, iStatus ); // make a request to remote device for getting a file, this will trigger to call RunL();
How to request for folder listing
When the file has been received then RunL will be called. The file can be saved by calling WritetoFile() method of CObexBufObject class. This is shown in the following code.
switch ( iClientState )
if(iStatus.Int() == KErrNone)
iGetObject->WriteToFile(iFileNameToGet); // Save the file to the same name that was passed by resuest.