Symbian
 Developer Library

DEVELOPER LIBRARY

[Index] [Glossary] [Previous] [Next]



Location: FTPSESS.h
Link against: ftpsess.lib

Class CFTPSession

class CFTPSession : public CBase

Support

Supported from 6.0

Description

Abstracts the complexity of the full FTP protocol and exports only a few simplified APIs.

Derivation

CBaseBase class for all classes to be instantiated on the heap
CFTPSessionAbstracts the complexity of the full FTP protocol and exports only a few simplified APIs

Defined in CFTPSession:
Cancel(), ChangeDirectory(), Close(), Connect(), Connect(), CreateDirectory(), DeleteDirectory(), DeleteFile(), EASCII, EActive, EBinary, EExpand, ENoOverwrite, EOverwrite, EStream, EUninitialised, Eblock, Epassive, GetCurrentDirectory(), GetVersion(), ListDirectory(), NewL(), RenameFile(), RepresentationType, Restart(), Retrieve(), Store(), TConnectionMode, TOpenMode, TransferMode, ~CFTPSession()

Inherited from CBase:
operator new()


Construction and destruction


NewL()

static CFTPSession* NewL(MFtpSessionNotifier* aNotifier);

Description

Allocates and constructs a new FTP session object.

Parameters

MFtpSessionNotifier* aNotifier

Callback interface to notify the client of the completion of operations or to report errors. For each FTP session, the FTP client should instantiate an object of this type.

Return value

CFTPSession*

New FTP session object


~CFTPSession()

~CFTPSession();

Description

Destructor.

[Top]


Member functions


Connect()

virtual void Connect(const TSockAddr& aNetAddr, const TDesC8& aUserName, const TDesC8& aPassword, const TConnectionMode aConnectionMode=EActive)=0;

Description

Connects to a remote FTP server, specifying the FTP server by a numeric IP address.

Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::ConnectionError(), or MFtpSessionNotifier::EUnknownError().

Parameters

const TSockAddr& aNetAddr

FTP server's IP address

const TDesC8& aUserName

User name to log on the FTP server

const TDesC8& aPassword

Password to identify to the FTP server

const TConnectionMode aConnectionMode=EActive

Connection mode (passive or active, see RFC959). You must use passive mode if the client is behind a firewall.


Connect()

virtual void Connect(const THostName& aServerName, const TDesC8& aUserName, const TDesC8& aPassword, const TConnectionMode aConnectionMode=EActive, const TUint aPort=KDefaultServerPiPort)=0;

Description

Connects to a remote FTP server, specifying the FTP server by a DNS name.

Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::ConnectionError(), or MFtpSessionNotifier::EUnknownError().

Parameters

const THostName& aServerName

FTP server's DNS name

const TDesC8& aUserName

User name to log on the FTP server

const TDesC8& aPassword

Password to identify to the FTP server

const TConnectionMode aConnectionMode=EActive

Connection mode (passive or active, see RFC959). You must use passive mode if the client is behind a firewall.

const TUint aPort=KDefaultServerPiPort

Port to connect to initiate the PI connection (see RFC959)


Close()

virtual void Close()=0;

Description

Closes the current connection with the FTP server.

Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), MFtpSessionNotifier::ConnReset(), or MFtpSessionNotifier::EUnknownError().

This cannot be called when an operation is in progress.


Cancel()

virtual void Cancel()=0;

Description

Cancels the last operation.

Cancel is only implemented for lengthy operations, that is: Connect(), Store(), Retrieve(), and ListDirectory(). For these operations, once cancel has been called, the MFtpSessionNotifier::Cancel() callback is called.

For other operations, calling cancel has no effect (it would take longer to wait for an acknowledgement to the Cancel, than waiting for the result of the current operation). However, a completion callback will be called, as well as MFtpSessionNotifier::Cancel().


Restart()

virtual void Restart(const TUint aTFTPRestartOffset)=0;

Description

After a connection is re-established, restarts the last aborted transfer operation (i.e. Store/Retrieve).

It is the responsibility of the client to remember and reset the state of the connection before attempting to resume the transfer: i.e. the client should re-establish the connection to the server and return to the relevant directory, then it should issue the Restart command with the offset it has saved, and then issue the Store or Retrieve command.

The Restart command should be avoided if the transfer was done in ASCII mode, as, because the server peforms a conversion on the bytestream format that it gets from the file before sending, the file size on the receiving end will be different than the size on the sending end. This means it is not possible to compute an offset for the sending end.

Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::OperationNotSupported(), or MFtpSessionNotifier::EUnknownError().

Parameters

const TUint aTFTPRestartOffset

An offset in bytes in the file from where transfer is to be resumed


Store()

virtual void Store(const TDesC& aLocalFileName, const TDesC8& aNewRemoteFileName, const TBool aOverwrite=EFalse, const RepresentationType aRepresentationType=EBinary, const TransferMode aTransferMode=EStream)=0;

Description

Transfers a file to the FTP server.

Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::ConnectionError(), MFtpSessionNotifier::LocalFileSystemError(), MFtpSessionNotifier::RemoteFileSystemError() or MFtpSessionNotifier::EUnknownError().

Parameters

const TDesC& aLocalFileName

Name of the local file to be transferred

const TDesC8& aNewRemoteFileName

Name of the remote file to be created

const TBool aOverwrite=EFalse

If true, overwrite a remote file with the same name if it exists; if false, fail if a remote file with the same name exists

const RepresentationType aRepresentationType=EBinary

The representation type of the transferred file, ASCII or Binary

const TransferMode aTransferMode=EStream

The transfer mode, stream mode or block mode. This is ignored and assumed to be stream, as block mode seems to be obsolete.


Retrieve()

virtual void Retrieve(const TDesC8& aRemoteFileName, const TDesC& aNewLocalFileName, const TOpenMode aOpenMode=EOverwrite, const RepresentationType aRepresentationType=EBinary, const TransferMode aTransferMode=EStream)=0;

Description

Transfers a file from the FTP server.

Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::LocalFileSystemError(), MFtpSessionNotifier::RemoteFileSystemError() or MFtpSessionNotifier::EUnknownError().

Parameters

const TDesC8& aRemoteFileName

The remote file Name

const TDesC& aNewLocalFileName

Name of the local file to be created

const TOpenMode aOpenMode=EOverwrite

Specifies whether to overwrite a local file with the same name if it already exists

const RepresentationType aRepresentationType=EBinary

The representation type of the transferred file, ASCII or Binary

const TransferMode aTransferMode=EStream

The transfer mode, stream mode or block mode. This is ignored and assumed to be stream, as block mode seems to be obsolete.


ChangeDirectory()

virtual void ChangeDirectory(const TDesC8& aDirectoryName)=0;

Description

Sets the current directory on the remote file system.

Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::RemoteFileSystemError() or MFtpSessionNotifier::EUnknownError().

Parameters

const TDesC8& aDirectoryName

Directory name


CreateDirectory()

virtual void CreateDirectory(const TDesC8& aDirectoryName)=0;

Description

Creates a directory on the remote file system.

Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::RemoteFileSystemError() or MFtpSessionNotifier::EUnknownError().

Parameters

const TDesC8& aDirectoryName

A directory name. This can be absolute or relative.


DeleteDirectory()

virtual void DeleteDirectory(const TDesC8& aDirectoryName)=0;

Description

Deletes a directory on the remote file system.

Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::RemoteFileSystemError() or MFtpSessionNotifier::EUnknownError().

Parameters

const TDesC8& aDirectoryName

A directory name. This can be absolute or relative.


GetCurrentDirectory()

virtual void GetCurrentDirectory()=0;

Description

Gets the client's current directory on the remote file system.

The result is returned to the MFtpSessionNotifier::ServerMessage() callback. The directory name is defined by the RFC as being enclosed between double quotes: for example, an answer will look like:

257 "/developr/rfc" is current directory.

The client must implement a parser to find the text between quotes.

The result can be passed in two or more consecutive calls of ServerMessage(). For example:

First call of ServerMessage: 257 "/developr

Second call of ServerMessage: /rfc" is current directory.

Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::RemoteFileSystemError() or MFtpSessionNotifier::EUnknownError().


ListDirectory()

virtual void ListDirectory(const TDesC8& aDirectoryName, TDes8& aFileList)=0;

Description

Lists the files in a directory on the remote file system.

On successful completion, the aFileList buffer contains the list of files as transmitted by the server. It is the responsibility of the client to parse this buffer to extract relevant information. aFileList is always appended to, so the client should set its current length to a meaningful value (i.e. 0, to fill the buffer from scratch).

If the list of files is larger than the aFileList buffer, MFtpSessionNotifier::MoreData() is called. At this point, the client must reissue the ListDirectory() request until the MFtpSessionNotifier::Complete() is called.

Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::RemoteFileSystemError() or MFtpSessionNotifier::EUnknownError().

Parameters

const TDesC8& aDirectoryName

A directory name. This can be absolute or relative.

TDes8& aFileList

On completion, the file list. The buffer is allocated by the client.


DeleteFile()

virtual void DeleteFile(const TDesC8& aFileName)=0;

Description

Deletes a file on the remote file system.

Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::RemoteFileSystemError() or MFtpSessionNotifier::EUnknownError().

Parameters

const TDesC8& aFileName

A file name


RenameFile()

virtual void RenameFile(const TDesC8& aRemoteFileName, const TDesC8& aNewRemoteFileName)=0;

Description

Renames a file on the remote file system.

Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::RemoteFileSystemError() or MFtpSessionNotifier::EUnknownError().

Parameters

const TDesC8& aRemoteFileName

An existing file name

const TDesC8& aNewRemoteFileName

A new file name


GetVersion()

static TUint32 GetVersion(void);

Description

Gets API version information.

The vesion information format is:

Return value

TUint32

Version information

[Top]


Enum TConnectionMode

TConnectionMode

Description

FTP connection mode (passive or active see RFC959).

EActive

Active mode.

Epassive

Passive mode.

[Top]


Enum RepresentationType

RepresentationType

Description

Representation type of a transferred file.

EUninitialised

Uninitialised.

EBinary

Binary.

EASCII

ASCII.

[Top]


Enum TransferMode

TransferMode

Description

FTP file transfer mode.

EStream

Stream mode.

Eblock

Block mode.

[Top]


Enum TOpenMode

TOpenMode

Description

FTP file open mode.

EOverwrite

Overwrite existing file.

ENoOverwrite

Do not overwrite existing file.

EExpand

Expand existing file.