How to pull a file from remote device with obex

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Created: mahbub_s60 (21 Jun 2010)
Last edited: hamishwillee (31 May 2013)



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
CObexClient* iClient;
CBufFlat* iObjectBuffer;
CObexBufObject* iGetObject;
TFileName iFileNameToGet;

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 )
delete iGetObject;
iGetObject = NULL;
if ( iObjectBuffer )
delete iGetObject;
iObjectBuffer = NULL;
iObjectBuffer = CBufFlat::NewL( KBTSUDataBufferExpandSize );
iGetObject = CObexBufObject::NewL( iObjectBuffer );
const TUint8 KNameHeaderHi = 0x01;
CObexHeader* nameHeader = CObexHeader::NewL();
nameHeader->SetUnicodeL(KNameHeaderHi, aFileName);
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.

void CMyBTBrowserObexClient::RunL()
switch ( iClientState )
case EBTSCliGettingFile:
if(iStatus.Int() == KErrNone)
iGetObject->WriteToFile(iFileNameToGet); // Save the file to the same name that was passed by resuest.

Related wiki articles

Remote Folder Browsing over

This page was last modified on 31 May 2013, at 02:27.
42 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.