williamr@2: /** williamr@2: * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@2: * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members williamr@2: * which accompanies this distribution, and is available williamr@2: * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: williamr@2: * EPOC32 FTP Engine header file williamr@2: * Author: Philippe Gabriel williamr@2: * Exports set of APIs simplyfying access to the FTP protocol williamr@2: * williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: /** williamr@2: @file FTPSESS.H williamr@2: @internalComponent williamr@2: */ williamr@2: williamr@2: #if !defined(__FTPSESS_H__) williamr@2: #define __FTPSESS_H__ williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: /** williamr@2: The very first release williamr@2: */ williamr@2: williamr@2: /** FTPSESS.DLL major version number. */ williamr@2: #define FTPSESS_VERSION_MAJOR 0x01 // The very first release williamr@2: /** FTPSESS.DLL minor version number. */ williamr@2: #define FTPSESS_VERSION_MINOR 0x03 williamr@2: /** FTPSESS.DLL version number. */ williamr@2: #define FTPSESS_VERSION_NUMBER (FTPSESS_VERSION_MAJOR<<8)|FTPSESS_VERSION_MINOR williamr@2: williamr@2: // Following Def as per RFC 959 williamr@2: /** Default server port. williamr@2: @internalComponent */ williamr@2: const TUint KDefaultServerPiPort = 21; williamr@2: // williamr@2: // MInterface definition to provide callback functions to the client williamr@2: // williamr@2: williamr@2: class MFtpSessionNotifier williamr@2: /** FTP session callback interface. williamr@2: * williamr@2: * An FTP session client implements this interface to receive status and results williamr@2: * from asynchronous FTP operations. williamr@2: * williamr@2: * Note that, as defined in RFC959, FTP does not allow concurrent execution of williamr@2: * several requests. Hence, even though calling an FTP function and getting the williamr@2: * result through this interface are asynchronous operations, these events happen williamr@2: * in a sequential manner. Each notification that the client receives corresponds williamr@2: * to only one currently outstanding operation. williamr@2: * @internalComponent williamr@2: */ williamr@2: { williamr@2: public: williamr@2: // williamr@2: // Operation completion return codes. williamr@2: // williamr@2: /** FTP engine/session operation completeness codes. */ williamr@2: enum TOpComp williamr@2: { williamr@2: /** Operation completed normally. */ williamr@2: EOpComplete=0, // No error williamr@2: /** Operation cancelled. */ williamr@2: EOpCanceled, // User canceled last operation williamr@2: williamr@2: //Connection errors williamr@2: /** Connection error: Connect address invalid. */ williamr@2: EHostNotExist, // Connect address invalid williamr@2: /** Connection error: Sockets level error. */ williamr@2: ESocketError, // Problem with socket operation williamr@2: /** Connection error: Connection failed. */ williamr@2: EConnectionFailed, // Can't connect to FTP port williamr@2: /** Connection error: Password needed. */ williamr@2: EPasswordNeeded, williamr@2: /** Connection error: Anonymous login not permitted. */ williamr@2: EAccountNeeded, // i.e. anonymous login disallowed williamr@2: /** Connection error: UserName, Password combination invalid. */ williamr@2: ELoginFailed, // UserName,Password combination invalid williamr@2: /** Connection error: Not connected to a server. */ williamr@2: ENotConnected, // Not connected to a server williamr@2: /** Connection error: Already connected to a server. */ williamr@2: EAlreadyConnected, // Already connected to a server williamr@2: /** Connection error: Operation timed out. */ williamr@2: ETimedOut, // Inactive for too long williamr@2: williamr@2: //Local filesystem errors williamr@2: /** Local filesystem error: General file system error. */ williamr@2: EFileSystemError, williamr@2: /** Local filesystem error: File opening failure. */ williamr@2: EFileOpenFailure, williamr@2: /** Local filesystem error: File reading failure. */ williamr@2: EFileReadError, williamr@2: /** Local filesystem error: File writing failure. */ williamr@2: EFileWriteError, williamr@2: /** Local filesystem error: File already exists. */ williamr@2: EFileAlreadyExist, williamr@2: /** Local filesystem error: File does not exist. */ williamr@2: EFileNotExist, williamr@2: /** Local filesystem error: Directory already exists. */ williamr@2: EDirAlreadyExist, williamr@2: /** Local filesystem error: Directory does not exist. */ williamr@2: EDirNotExist, williamr@2: williamr@2: // Permission error williamr@2: /** Permission error: Permission denied. */ williamr@2: EPermissionDenied, williamr@2: williamr@2: //Remote filesystem errors williamr@2: /** Remote filesystem error: General remote file system error. */ williamr@2: ERemoteFileSystemError, williamr@2: /** Remote filesystem error: Remote file opening failure. */ williamr@2: ERemoteFileOpenFailure, williamr@2: /** Remote filesystem error: Remote file reading failure. */ williamr@2: ERemoteFileReadError, williamr@2: /** Remote filesystem error: Remote file writing failure. */ williamr@2: ERemoteFileWriteError, williamr@2: /** Remote filesystem error: Remote file already exists. */ williamr@2: ERemoteFileAlreadyExist, williamr@2: /** Remote filesystem error: Remote file does not exist. */ williamr@2: ERemoteFileNotExist, williamr@2: /** Remote filesystem error: Remote directory already exists. */ williamr@2: ERemoteDirAlreadyExist, williamr@2: /** Remote filesystem error: Remote directory does not exist. */ williamr@2: ERemoteDirNotExist, williamr@2: /** Remote filesystem error: Restart is not supported. */ williamr@2: ERestartNotSupported williamr@2: }; williamr@2: williamr@2: /** Normal operation completion. */ williamr@2: virtual void Complete(void)=0; williamr@2: williamr@2: // Operation completed, more data to follow williamr@2: /** Operation partially completed, with more data to follow. */ williamr@2: virtual void MoreData(void)=0; williamr@2: williamr@2: /** Reports the amount of data already transferred in bytes. williamr@2: * williamr@2: * @param aProgress Amount of data already transferred */ williamr@2: virtual void TransferProgress(TUint aProgress)=0; williamr@2: williamr@2: /** User cancelled an on-going operation. */ williamr@2: virtual void Cancel(void)=0; williamr@2: williamr@2: /** Peer reset the connection. */ williamr@2: virtual void ConnReset(void)=0; williamr@2: williamr@2: /** Error in establishing the connection with the FTP server. williamr@2: * williamr@2: * @param aTConnectionError Operation completion code */ williamr@2: virtual void ConnectionError(TOpComp aTConnectionError)=0; williamr@2: williamr@2: // FTP server does not implement the operation requested williamr@2: /** Restart operation not supported. */ williamr@2: virtual void OperationNotSupported(void)=0; williamr@2: williamr@2: // Local File system error williamr@2: /** Error with the local file system. williamr@2: * williamr@2: * @param aTLocalFileSystemError Operation completion code */ williamr@2: virtual void LocalFileSystemError(TOpComp aTLocalFileSystemError)=0; williamr@2: williamr@2: // Remote File system error williamr@2: /** Error with the remote file system. williamr@2: * williamr@2: * @param aTRemoteFileSystemError Operation completion code */ williamr@2: virtual void RemoteFileSystemError(TOpComp aTRemoteFileSystemError)=0; williamr@2: williamr@2: // Not specified yet williamr@2: /** Unspecified error. */ williamr@2: virtual void EUnknownError()=0; williamr@2: williamr@2: // Message reported by server williamr@2: /** Message sent by the FTP server. williamr@2: * williamr@2: * As specified by the RFC, the server answers all requests from the williamr@2: * client with a plain text message beginning with a 3 digit code. williamr@2: * The error/completion notifications sent back by the FTP session API williamr@2: * are derived from these codes. Additionally, this function can be williamr@2: * used to get the full string reporting the result of the request. williamr@2: * It is recommended that the user interface displays this string to williamr@2: * the user, as this gives a more precise idea of the result of the williamr@2: * requested operation, especially in case of error. williamr@2: * williamr@2: * @param TDesC8 The message sent by the server */ williamr@2: virtual void ServerMessage(const TDesC8&)=0; williamr@2: }; williamr@2: // williamr@2: // The CFTPSession class williamr@2: // williamr@2: class CFTPSession : public CBase williamr@2: williamr@2: /** Abstracts the complexity of the full FTP protocol and exports only williamr@2: * a few simplified APIs. williamr@2: * @internalComponent */ williamr@2: { williamr@2: public: williamr@2: /** FTP connection mode (passive or active see RFC959). */ williamr@2: enum TConnectionMode williamr@2: { williamr@2: /** Active mode. Server initiates DTP connection to client. */ williamr@2: EActive=0, //(see RFC959) williamr@2: /** Passive mode. Client initiates DTP connection to server.*/ williamr@2: Epassive //(see RFC959) williamr@2: }; williamr@2: /** Representation type of a transferred file. */ williamr@2: enum RepresentationType williamr@2: { williamr@2: /** Uninitialised. */ williamr@2: EUninitialised=0, williamr@2: /** File transfered in Binary mode, no translation. */ williamr@2: EBinary, williamr@2: /** File transfered in ASCII mode, translation. */ williamr@2: EASCII williamr@2: }; williamr@2: /** FTP file transfer mode. */ williamr@2: enum TransferMode williamr@2: { williamr@2: /** Stream mode; file transfered as a stream of bytes. */ williamr@2: EStream=0, williamr@2: /** Block mode; file transfered as blocks, with header needed to restart aborted transfer. */ williamr@2: Eblock williamr@2: }; williamr@2: /** FTP file open mode. */ williamr@2: enum TOpenMode williamr@2: { williamr@2: /** Overwrite existing file. */ williamr@2: EOverwrite, williamr@2: /** Do not overwrite existing file. */ williamr@2: ENoOverwrite, williamr@2: /** Expand existing file. */ williamr@2: EExpand williamr@2: }; williamr@2: williamr@2: /** Construction */ williamr@2: public: williamr@2: williamr@2: // williamr@2: // Connection APIs williamr@2: // williamr@2: // Establish a connection with a server: williamr@2: /** Connects to a remote FTP server, specifying the FTP server by a numeric IP williamr@2: * address. williamr@2: * williamr@2: * Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), williamr@2: * MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::ConnectionError(), williamr@2: * or MFtpSessionNotifier::EUnknownError(). williamr@2: * williamr@2: * @param aNetAddr FTP server's IP address williamr@2: * @param aUserName User name to log on the FTP server williamr@2: * @param aPassword Password to identify to the FTP server williamr@2: * @param aConnectionMode Connection mode (passive or active, see RFC959). williamr@2: * You must use passive mode if the client is behind a firewall. */ williamr@2: virtual void Connect( const TSockAddr& aNetAddr, //IP address williamr@2: const TDesC8& aUserName, williamr@2: const TDesC8& aPassword, williamr@2: const TConnectionMode aConnectionMode=EActive)=0; williamr@2: williamr@2: williamr@2: /** Connects to a remote FTP server, specifying the FTP server by a DNS name. williamr@2: * williamr@2: * Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), williamr@2: * MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::ConnectionError(), williamr@2: * or MFtpSessionNotifier::EUnknownError(). williamr@2: * williamr@2: * @param aServerName FTP server's DNS name williamr@2: * @param aUserName User name to log on the FTP server williamr@2: * @param aPassword Password to identify to the FTP server williamr@2: * @param aConnectionMode Connection mode (passive or active, see RFC959). You williamr@2: * must use passive mode if the client is behind a firewall. williamr@2: * @param aPort Port to connect to initiate the PI connection (see RFC959) */ williamr@2: virtual void Connect( const THostName& aServerName, //DNS name williamr@2: const TDesC8& aUserName, williamr@2: const TDesC8& aPassword, williamr@2: const TConnectionMode aConnectionMode=EActive, williamr@2: const TUint aPort=KDefaultServerPiPort)=0; williamr@2: williamr@2: williamr@2: // Close connection with a server williamr@2: /** Closes the current connection with the FTP server. williamr@2: * williamr@2: * Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), williamr@2: * MFtpSessionNotifier::ConnReset(), or MFtpSessionNotifier::EUnknownError(). williamr@2: * williamr@2: * This cannot be called when an operation is in progress. */ williamr@2: virtual void Close()=0; williamr@2: williamr@2: williamr@2: // Cancel last FTP operation williamr@2: /** Cancels the last FTP operation. williamr@2: * williamr@2: * Cancel is only implemented for lengthy operations, that is: Connect(), Store(), williamr@2: * Retrieve(), and ListDirectory(). For these operations, once cancel has been williamr@2: * called, the MFtpSessionNotifier::Cancel() callback is called. williamr@2: * williamr@2: * For other operations, calling Cancel() has no effect (it would take longer to williamr@2: * wait for an acknowledgement to the Cancel(), than waiting for the result of williamr@2: * the current operation). However, a completion callback will be called, as williamr@2: * well as MFtpSessionNotifier::Cancel(). */ williamr@2: virtual void Cancel()=0; williamr@2: williamr@2: williamr@2: // Restart an aborted transfer operation williamr@2: /** After a connection is re-established, restarts the last aborted transfer operation williamr@2: * (i.e. Store/Retrieve). williamr@2: * williamr@2: * It is the responsibility of the client to remember and reset the state of williamr@2: * the connection before attempting to resume the transfer: i.e. the client should williamr@2: * re-establish the connection to the server and return to the relevant directory, williamr@2: * then it should issue the Restart() command with the offset it has saved, and williamr@2: * then issue the Store() or Retrieve() command. williamr@2: * williamr@2: * The Restart() command should be avoided if the transfer was done in ASCII mode, williamr@2: * as, because the server peforms a conversion on the bytestream format that williamr@2: * it gets from the file before sending, the file size on the receiving end will williamr@2: * be different than the size on the sending end. This means it is not possible williamr@2: * to compute an offset for the sending end. williamr@2: * williamr@2: * Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), williamr@2: * MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::OperationNotSupported(), williamr@2: * or MFtpSessionNotifier::EUnknownError(). williamr@2: * williamr@2: * @param aTFTPRestartOffset An offset in bytes in the file from where transfer williamr@2: * is to be resumed */ williamr@2: virtual void Restart(const TUint aTFTPRestartOffset)=0; williamr@2: williamr@2: // williamr@2: // Transfer APIs williamr@2: // williamr@2: // Store a file on the server williamr@2: /** Transfers a file to the FTP server. williamr@2: * williamr@2: * Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), williamr@2: * MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::ConnectionError(), williamr@2: * MFtpSessionNotifier::LocalFileSystemError(), MFtpSessionNotifier::RemoteFileSystemError() williamr@2: * or MFtpSessionNotifier::EUnknownError(). williamr@2: * williamr@2: * @param aLocalFileName Name of the local file to be transferred williamr@2: * @param aNewRemoteFileName Name of the remote file to be created williamr@2: * @param aOverwrite If ETrue, overwrite a remote file with the same name if it williamr@2: * exists; if EFalse, fail if a remote file with the same name exists williamr@2: * @param aRepresentationType The representation type of the transferred file, ASCII or Binary williamr@2: * @param aTransferMode The transfer mode, stream mode or block mode. This is williamr@2: * ignored and assumed to be stream, as block mode seems to be obsolete. */ williamr@2: virtual void Store( const TDesC& aLocalFileName, williamr@2: const TDesC8& aNewRemoteFileName, williamr@2: const TBool aOverwrite = EFalse, williamr@2: const RepresentationType aRepresentationType = EBinary, williamr@2: const TransferMode aTransferMode = EStream)=0; williamr@2: williamr@2: williamr@2: // Get a file from the server williamr@2: /** Transfers a file from the FTP server. williamr@2: * williamr@2: * Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), williamr@2: * MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::LocalFileSystemError(), williamr@2: * MFtpSessionNotifier::RemoteFileSystemError() or MFtpSessionNotifier::EUnknownError(). williamr@2: * williamr@2: * @param aRemoteFileName The remote file Name williamr@2: * @param aNewLocalFileName Name of the local file to be created williamr@2: * @param aOpenMode Specifies whether to overwrite a local file with the same williamr@2: * name if it already exists williamr@2: * @param aRepresentationType The representation type of the transferred file, williamr@2: * ASCII or Binary williamr@2: * @param aTransferMode The transfer mode, stream mode or block mode. This is williamr@2: * ignored and assumed to be stream, as block mode seems to be obsolete. */ williamr@2: virtual void Retrieve( const TDesC8& aRemoteFileName, williamr@2: const TDesC& aNewLocalFileName, williamr@2: const TOpenMode aOpenMode = EOverwrite, williamr@2: const RepresentationType aRepresentationType = EBinary, williamr@2: const TransferMode aTransferMode = EStream)=0; williamr@2: williamr@2: williamr@2: // williamr@2: // File system management functions williamr@2: // williamr@2: /** Sets the current directory on the remote file system. williamr@2: * williamr@2: * Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), williamr@2: * MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::RemoteFileSystemError() williamr@2: * or MFtpSessionNotifier::EUnknownError(). williamr@2: * williamr@2: * @param aDirectoryName Directory name */ williamr@2: virtual void ChangeDirectory(const TDesC8& aDirectoryName)=0; williamr@2: williamr@2: williamr@2: /** Creates a directory on the remote file system. williamr@2: * williamr@2: * Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), williamr@2: * MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::RemoteFileSystemError() williamr@2: * or MFtpSessionNotifier::EUnknownError(). williamr@2: * williamr@2: * @param aDirectoryName A directory name. This can be absolute or relative. */ williamr@2: virtual void CreateDirectory(const TDesC8& aDirectoryName)=0; williamr@2: williamr@2: williamr@2: /** Deletes a directory on the remote file system. williamr@2: * williamr@2: * Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), williamr@2: * MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::RemoteFileSystemError() williamr@2: * or MFtpSessionNotifier::EUnknownError(). williamr@2: * williamr@2: * @param aDirectoryName A directory name. This can be absolute or relative. */ williamr@2: virtual void DeleteDirectory(const TDesC8& aDirectoryName)=0; williamr@2: williamr@2: williamr@2: /** Gets the client's current directory on the remote file system. williamr@2: * williamr@2: * The result is returned to the MFtpSessionNotifier::ServerMessage() callback. williamr@2: * The directory name is defined by the RFC as being enclosed between double williamr@2: * quotes: for example, an answer will look like: williamr@2: * williamr@2: * @code williamr@2: * 257 "/developr/rfc" is current directory. williamr@2: * @endcode williamr@2: * The client must implement a parser to find the text between quotes. williamr@2: * williamr@2: * The result can be passed in two or more consecutive calls of MFtpSessionNotifier::ServerMessage(). williamr@2: * For example: williamr@2: * williamr@2: * First call of MFtpSessionNotifier::ServerMessage(): @code 257 "/developr @endcode williamr@2: * williamr@2: * Second call of MFtpSessionNotifier::ServerMessage(): @code /rfc" is current directory. @endcode williamr@2: * williamr@2: * Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), williamr@2: * MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::RemoteFileSystemError() williamr@2: * or MFtpSessionNotifier::EUnknownError(). */ williamr@2: virtual void GetCurrentDirectory(void)=0; williamr@2: williamr@2: williamr@2: /** Lists the files in a directory on the remote file system. williamr@2: * williamr@2: * On successful completion, the aFileList buffer contains the list of files williamr@2: * as transmitted by the server. It is the responsibility of the client to parse williamr@2: * this buffer to extract relevant information. aFileList is always appended williamr@2: * to, so the client should set its current length to a meaningful value (i.e. williamr@2: * 0, to fill the buffer from scratch). williamr@2: * williamr@2: * If the list of files is larger than the aFileList buffer, MFtpSessionNotifier::MoreData() williamr@2: * is called. At this point, the client must reissue the ListDirectory() request williamr@2: * until the MFtpSessionNotifier::Complete() is called. williamr@2: * williamr@2: * Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), williamr@2: * MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::RemoteFileSystemError() williamr@2: * or MFtpSessionNotifier::EUnknownError(). williamr@2: * williamr@2: * @param aDirectoryName A directory name. This can be absolute or relative. williamr@2: * @param aFileList On completion, the file list. The buffer is allocated by the client. */ williamr@2: virtual void ListDirectory(const TDesC8& aDirectoryName, williamr@2: TDes8& aFileList)=0; williamr@2: williamr@2: williamr@2: /** Deletes a file on the remote file system. williamr@2: * williamr@2: * Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), williamr@2: * MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::RemoteFileSystemError() williamr@2: * or MFtpSessionNotifier::EUnknownError(). williamr@2: * williamr@2: * @param aFileName A file name */ williamr@2: virtual void DeleteFile(const TDesC8& aFileName)=0; williamr@2: williamr@2: /** Renames a file on the remote file system. williamr@2: * williamr@2: * Completion is indicated by a callback to one of MFtpSessionNotifier::Complete(), williamr@2: * MFtpSessionNotifier::ConnReset(), MFtpSessionNotifier::RemoteFileSystemError() williamr@2: * or MFtpSessionNotifier::EUnknownError(). williamr@2: * williamr@2: * @param aRemoteFileName An existing file name williamr@2: * @param aNewRemoteFileName A new file name */ williamr@2: virtual void RenameFile(const TDesC8& aRemoteFileName, williamr@2: const TDesC8& aNewRemoteFileName)=0; williamr@2: williamr@2: williamr@2: /** williamr@2: Returns 32-bit, with williamr@2: ftpsess dll MAJOR_VERSION in msb of the msw williamr@2: ftpsess dll MINOR_VERSION in lsb of the msw williamr@2: ftpprot dll MAJOR_VERSION in msb of the lsw williamr@2: ftpprot dll MINOR_VERSION in lsb of the lsw williamr@2: */ williamr@2: IMPORT_C static TUint32 GetVersion(void); williamr@2: williamr@2: /** Allocates and constructs a new FTP session object. williamr@2: * williamr@2: * @param aNotifier Callback interface to notify the client of the completion of williamr@2: * operations or to report errors. For each FTP session, the FTP williamr@2: * client should instantiate an object of this type. williamr@2: * @return New FTP session object williamr@2: */ williamr@2: IMPORT_C static CFTPSession* NewL(MFtpSessionNotifier* aNotifier); williamr@2: williamr@2: /**Destructor.*/ williamr@2: virtual ~CFTPSession(); williamr@2: }; williamr@2: #endif