NFtp Class Reference

FTP Protocol Implementation using the NNet interface. More...

#include <nftp.h>

Inheritance diagram for NFtp:

NNet

Public Types

enum  logType {
  NERR = 0, NINFO, NREPLY, NCOMMAND,
  NCUSTOM, NOTHER
}
 Specifies the classification of the log(). More...

enum  errorType {
  ErrNo = 0, ErrHostInvalid, ErrHostNotFound, ErrConnectionRefused,
  ErrNotConnected, ErrConnected, ErrSocketBusy, ErrFileSeek,
  ErrUnknown
}
 Specifies the classification of the error returned. More...

enum  Operations {
  OpList = 0, OpGet, OpPut, OpCWD,
  OpFxp, OpRemove, OpRaw, OpIdle,
  OpConnecting, OpInvalid
}
 Specifies the classification of the current operation. More...


Public Slots

virtual int closeConnection ()
 Disconnect from remote system.


Signals

void log (int id, NNet::logType type, QString msg)
 Any commands sent, replies given, errors, warnings, or other info should emit a log signal with a NNet::logType classification and a human readable string.

void connectionClosed (int id, NHostInfo hInfo)
 Connection to the remote system was closed.

void changedDirectory (int id, const QString &dirname)
 Directory on remote system changed.

void connected (int id, NHostInfo hInfo)
 Connection opened.

void transferProgress (int id, unsigned int current, unsigned int total)
 Transfer Progress changed.

void transferComplete (int id, bool finished, uint bytes, int time, double rate)
 Transfer completed.

void directoryListing (int id, const QValueList< QUrlInfo > &dirList)
 Directory listing from remote system.

void loginComplete (int id)
 Login proccess completed.


Public Member Functions

 NFtp (int id, QObject *parent=0, const char *name=0)
 Create a new NFtp object with an ID of id.

virtual const char * name () const
 Returns the name the implementation refers to itself as.

virtual const char * protocol () const
 Returns the url prefix for the protocol implemented.

virtual int connectToHost (NHostInfo hInfo, bool batch)
 Connects to the host specified.

virtual int sendRawCommand (QString command)
 Send a custom command to the server.

virtual int list ()
 Request a directory listing.

virtual int cd (QString dir)
 Changes the current directory.

virtual int move (QString newname, QString oldname)
 Moves a file from one place to another.

virtual int remove (QString name, bool recursive=false)
 Removes a remote file/directory.

virtual int makedir (QString dir)
 Create a directory.

virtual int abort ()
 Abort current operation.

virtual int get (QString file, QString sourcefile, bool resume=false)
 Retrieves a single file.

virtual int put (QString file, QString sourcefile, bool resume=false)
 Uploads a single file.

virtual const NHostInfo getHostInfo () const
 Returns the host information for the current connection.

virtual bool isConnected () const
 Returns a boolean affirmation that the object is connected and ready for commands.

virtual int currentOperation () const
 Returns the state of the object in the form of a NNet::Operations enum.


Protected Member Functions

virtual QCString findDirCache (QString dir, int timeout=-1) const
 Locate directory cache for the requested directory.

virtual void addDirCache (QString dir, QCString dirListing)
 Adds a directory listing to the cache.

virtual void clearDirCache ()
 Clears the directory cache.

QString getAppSetting (QString setName, QString defVal="") const
 Get a setting from the applications settings.

int getAppSetting (QString setName, int defVal) const
 Get a setting from the applications settings.

QString getProtSetting (QString setName, QString defVal="") const
 Get a setting that is specific to the protocol.

int getProtSetting (QString setName, int defVal) const
 Get a setting that is specific to the protocol.

QString getHostSetting (QString setName, QString defVal="") const
 Get a setting that is specific to the hostInfo.

int getHostSetting (QString setName, int defVal) const
 Get a setting that is specific to the hostInfo.


Protected Attributes

int _id
 ID of this object. Used for all signals.

QSocket * commandSock
 QSocket for use as the main communications socket.

QSocket * dataSock
 QSocket for the secondary socket if the protocol requires it.

NHostInfo hostInfo
 Holds the most up to date information regarding the connection.

bool commandDelayedClose
 Boolean state marker for if the command socket is performing a delayed close.

bool dataDelayedClose
 Boolean state marker for if the data socket is performing a delayed close.

bool commandReady
 Boolean state marker signifying that the connection is ready to accept operations.

bool expectedClose
 Boolean state marker signifying that a connection close is expected.

bool _batch
 Marks if this object is meant to be used for batch operations, or user interaction.

QCString currentDirListing
 Holds the raw directory listing of the current directory, if available.

Operations currentOp
 Holds the current operation.


Detailed Description

FTP Protocol Implementation using the NNet interface.


Member Enumeration Documentation

enum NNet::errorType [inherited]
 

Specifies the classification of the error returned.

Enumeration values:
ErrNo  No error, requested operation succeeded.
ErrHostInvalid  URL given is invalid.
ErrHostNotFound  Hostname failed to resolve.
ErrConnectionRefused  Host refused connection attempt.
ErrNotConnected  Object not connected, Invalid request.
ErrConnected  Already connected.
ErrSocketBusy  Socket already busy, operation unable to proceed.
ErrFileSeek  File read error.
ErrUnknown  Unknown error, unable to proceed.

enum NNet::logType [inherited]
 

Specifies the classification of the log().

Enumeration values:
NERR  Errors.
NINFO  Informational.
NREPLY  Replies from the remote system.
NCOMMAND  Commands sent from the client.
NCUSTOM  Replies from the remote system that originated due to a sendRawCommand().
NOTHER  Anything else that doesn't fit the above classifications.

enum NNet::Operations [inherited]
 

Specifies the classification of the current operation.

Enumeration values:
OpList  Listing directory.
OpGet  Retrieving a file from the remote system.
OpPut  Uploading a file to the remote system.
OpCWD  Changing directories.
OpFxp  FXP operation.
OpRemove  Removing files from remote system, likely recursively.
OpRaw  Performing a custom command as given by sendRawCommand().
OpIdle  Idle, no operation in progress.
OpConnecting  Connecting to remote system.
OpInvalid  Not connected.


Constructor & Destructor Documentation

NFtp::NFtp int  id,
QObject *  parent = 0,
const char *  name = 0
 

Create a new NFtp object with an ID of id.


Member Function Documentation

int NFtp::abort  )  [virtual]
 

Abort current operation.

Request an abortion of the current operation from the remote system. The abort should attempt to recover the session into a reusable state.

Returns:
ErrNotConnected if no remote system is connected.

ErrUnknown if the operation is unhandled.

ErrNo if the operation was started successfully.

Implements NNet.

void NNet::addDirCache QString  dir,
QCString  dirListing
[protected, virtual, inherited]
 

Adds a directory listing to the cache.

Parameters:
dir Absolute path of the directory listing to store.
dirListing Raw directory listing to store.

int NFtp::cd QString  dir  )  [virtual]
 

Changes the current directory.

Changes the directory on the remote system. If the protocol does not support persistent sessions, the protocol implementation should still remember the "current" directory as known to the object.

Returns:
ErrNotConnected if no remote system is connected.

ErrUnknown if the operation is unhandled.

ErrNo if the operation was started successfully.

Implements NNet.

void NNet::changedDirectory int  id,
const QString &  dirname
[signal, inherited]
 

Directory on remote system changed.

Parameters:
id ID of this object (_id)
dirname Absolute path (on remote system) of new current directory.

void NNet::clearDirCache  )  [protected, virtual, inherited]
 

Clears the directory cache.

int NFtp::closeConnection  )  [virtual, slot]
 

Disconnect from remote system.

Disconnect object from any remote connections and return it to a usable, unconnected, state.

Returns:
ErrNo if the disconnect was successful.

Implements NNet.

void NNet::connected int  id,
NHostInfo  hInfo
[signal, inherited]
 

Connection opened.

Parameters:
id ID of this object (_id)
hInfo URL of the remote system newly connected.

void NNet::connectionClosed int  id,
NHostInfo  hInfo
[signal, inherited]
 

Connection to the remote system was closed.

Parameters:
id ID of this object (_id)
hInfo Last valid URL for the connection, including protocol, host, port, username, and password.

int NFtp::connectToHost NHostInfo  hInfo,
bool  batch
[virtual]
 

Connects to the host specified.

Parameters:
hInfo URL of host to connect to, including username, password, port, and initial directory.
batch Specifies if the connection should perform an initial directory listing.
Returns:
ErrConnected if the object is already connected.

ErrHostInvalid if the given URL is invalid.

ErrUnknown if the URL requests a protocol that we don't handle.

ErrNo if the operation was started successfully.

Implements NNet.

virtual int NNet::currentOperation  )  const [inline, virtual, inherited]
 

Returns the state of the object in the form of a NNet::Operations enum.

Returns:
currentOp

void NNet::directoryListing int  id,
const QValueList< QUrlInfo > &  dirList
[signal, inherited]
 

Directory listing from remote system.

Parameters:
id ID of this object (_id)
dirList A pre-parsed QValueList containing QUrlInfo objects for each directory entry.

QCString NNet::findDirCache QString  dir,
int  timeout = -1
const [protected, virtual, inherited]
 

Locate directory cache for the requested directory.

Parameters:
dir Absolute path of the requested directory listing.
timeout Time in seconds that the cache entry must be newer than. Default will look up the application's setting for it.
Returns:
QCString of the raw directory listing, or an empty string if not found or expired.

int NFtp::get QString  file,
QString  sourcefile,
bool  resume = false
[virtual]
 

Retrieves a single file.

Requests file from the remote system, and save it to destfile on the local system. Protocol implementation is responsible for file creation. Resume should be attempted if protocol supports it, and resume is true; or if the protocol's AutoResume option is set to on.

Returns:
ErrNotConnected if no remote system is connected.

ErrSocketBusy if the current operation is not OpIdle.

ErrFileSeek if local file creation fails.

ErrUnknown if the operation is unhandled. This makes the implementation fairly useless, though.

ErrNo if the operation was started successfully.

Implements NNet.

int NNet::getAppSetting QString  setName,
int  defVal
const [protected, inherited]
 

Get a setting from the applications settings.

Overloaded version of above.

Parameters:
setName Name of the setting to retrieve.
defVal Default value to return if the setting does not exist.

QString NNet::getAppSetting QString  setName,
QString  defVal = ""
const [protected, inherited]
 

Get a setting from the applications settings.

Parameters:
setName Name of the setting to retrieve.
defVal Default value to return if the setting does not exist.

virtual const NHostInfo NNet::getHostInfo  )  const [inline, virtual, inherited]
 

Returns the host information for the current connection.

Though virtual, the default implementation should be valid for most protocols.

Returns:
hostInfo

int NNet::getHostSetting QString  setName,
int  defVal
const [protected, inherited]
 

Get a setting that is specific to the hostInfo.

Overloaded version of the above. If the hostInfo does not contain a setting with that name, it will return the getProtSetting() for the same setName.

Parameters:
setName Name of the setting to retrieve.
defVal Default value to return if the setting does not exist.

QString NNet::getHostSetting QString  setName,
QString  defVal = ""
const [protected, inherited]
 

Get a setting that is specific to the hostInfo.

If the hostInfo does not contain a setting with that name, it will return the getProtSetting() for the same setName.

Parameters:
setName Name of the setting to retrieve.
defVal Default value to return if the setting does not exist.

int NNet::getProtSetting QString  setName,
int  defVal
const [protected, inherited]
 

Get a setting that is specific to the protocol.

Overloaded version of the above.

Parameters:
setName Name of the setting to retrieve.
defVal Default value to return if the setting does not exist.

QString NNet::getProtSetting QString  setName,
QString  defVal = ""
const [protected, inherited]
 

Get a setting that is specific to the protocol.

Parameters:
setName Name of the setting to retrieve.
defVal Default value to return if the setting does not exist.

virtual bool NNet::isConnected  )  const [inline, virtual, inherited]
 

Returns a boolean affirmation that the object is connected and ready for commands.

Returns:
commandReady

int NFtp::list  )  [virtual]
 

Request a directory listing.

Requests a directory listing from the remote system for the current directory. This function should not read from directory cache, but the result should be entered into it.

Returns:
ErrNotConnected if no remote system is connected.

ErrSocketBusy if the current operation is not OpIdle.

ErrUnknown if the operation is unhandled.

ErrNo if the operation was started successfully.

Implements NNet.

void NNet::log int  id,
NNet::logType  type,
QString  msg
[signal, inherited]
 

Any commands sent, replies given, errors, warnings, or other info should emit a log signal with a NNet::logType classification and a human readable string.

Parameters:
id ID of this object (_id)
type Classification of this message.
msg Human readable string containing message.

void NNet::loginComplete int  id  )  [signal, inherited]
 

Login proccess completed.

Implies that the connection sequence is completed and that the object is ready for further usage.

Parameters:
id ID of this object (_id)

int NFtp::makedir QString  dir  )  [virtual]
 

Create a directory.

Create a new directory named dir on the remote system. dir can be relative or absolute, and both should be accepted as valid.

Returns:
ErrNotConnected if no remote system is connected.

ErrUnknown if the operation is unhandled.

ErrNo if the operation was started successfully.

Implements NNet.

int NFtp::move QString  newname,
QString  oldname
[virtual]
 

Moves a file from one place to another.

Performs a move/rename operation on the remote system, moving oldname to newname.

Returns:
ErrNotConnected if no remote system is connected.

ErrUnknown if the operation is unhandled.

ErrNo if the operation was started successfully.

Implements NNet.

virtual const char* NFtp::name  )  const [inline, virtual]
 

Returns the name the implementation refers to itself as.

Defaults to whatever protocol() returns.

Reimplemented from NNet.

virtual const char* NFtp::protocol  )  const [inline, virtual]
 

Returns the url prefix for the protocol implemented.

Implements NNet.

int NFtp::put QString  file,
QString  sourcefile,
bool  resume = false
[virtual]
 

Uploads a single file.

Attempts to upload file from the remote system, reading it from local file sourcefile. Protocol implementation is responsible for making sure that the sourcefile exists and is readable. Resume should be attempted if the protocol supports it, and resume is true; or if the protocol's AutoResume option is set to on.

Returns:
ErrNotConnected if no remote system is connected.

ErrSocketBusy if the current operation is not OpIdle.

ErrFileSeek if local file is unreadable.

ErrUnknown if the operation is unhandled.

ErrNo if the operation was started successfully.

Implements NNet.

int NFtp::remove QString  name,
bool  recursive = false
[virtual]
 

Removes a remote file/directory.

Performs a file deletion on the remote system, of file name. If recursive is true, assume that name is a directory, and delete it and its contents recursively.

Returns:
ErrNotConnected if no remote system is connected.

ErrSocketBusy if the current operation is not OpIdle.

ErrUnknown if the operation is unhandled. Use this if recursivity is impossible, but requested.

ErrNo if the operation was started successfully.

Implements NNet.

int NFtp::sendRawCommand QString  command  )  [virtual]
 

Send a custom command to the server.

Bypassing any internal command manipulation, and reply parsing, send a single command to the remote system and expects replies from this command to come from log() with the NCUSTOM classification.

Returns:
ErrNotConnected if no remote system is connected.

ErrSocketBusy if the current operation is not OpIdle.

ErrUnknown if the operation is unhandled.

ErrNo if the operation was started successfully.

Implements NNet.

void NNet::transferComplete int  id,
bool  finished,
uint  bytes,
int  time,
double  rate
[signal, inherited]
 

Transfer completed.

Parameters:
id ID of this object (_id)
finished True if transfer was successful, False if it failed or was incomplete.
bytes Number of bytes transferred.
time Time elapsed in milliseconds.
rate Average transfer rate in kilobytes.

void NNet::transferProgress int  id,
unsigned int  current,
unsigned int  total
[signal, inherited]
 

Transfer Progress changed.

Parameters:
id ID of this object (_id)
current Number of bytes transferred so far.
total Total number of bytes in transfer. Use 0 if unknown.


Field Documentation

bool NNet::_batch [protected, inherited]
 

Marks if this object is meant to be used for batch operations, or user interaction.

int NNet::_id [protected, inherited]
 

ID of this object. Used for all signals.

bool NNet::commandDelayedClose [protected, inherited]
 

Boolean state marker for if the command socket is performing a delayed close.

bool NNet::commandReady [protected, inherited]
 

Boolean state marker signifying that the connection is ready to accept operations.

QSocket* NNet::commandSock [protected, inherited]
 

QSocket for use as the main communications socket.

QCString NNet::currentDirListing [protected, inherited]
 

Holds the raw directory listing of the current directory, if available.

Operations NNet::currentOp [protected, inherited]
 

Holds the current operation.

bool NNet::dataDelayedClose [protected, inherited]
 

Boolean state marker for if the data socket is performing a delayed close.

QSocket* NNet::dataSock [protected, inherited]
 

QSocket for the secondary socket if the protocol requires it.

bool NNet::expectedClose [protected, inherited]
 

Boolean state marker signifying that a connection close is expected.

NHostInfo NNet::hostInfo [protected, inherited]
 

Holds the most up to date information regarding the connection.


The documentation for this class was generated from the following files:
Generated on Wed Oct 22 20:32:04 2003 for nvemftp by doxygen1.3