QFtp Class Reference

#include <qftp.h>

Inheritance diagram for QFtp:

Inheritance graph
[legend]
Collaboration diagram for QFtp:

Collaboration graph
[legend]
List of all members.

Detailed Description

The QFtp class provides an implementation of the client side of FTP protocol.

network

The class works asynchronously, so there are no blocking functions. If an operation cannot be executed immediately, the function will still return straight away and the operation will be scheduled for later execution. The results of scheduled operations are reported via signals. This approach depends on the event loop being in operation.

The operations that can be scheduled (they are called "commands" in the rest of the documentation) are the following: connectToHost(), login(), close(), list(), cd(), get(), put(), remove(), mkdir(), rmdir(), rename() and rawCommand().

All of these commands return a unique identifier that allows you to keep track of the command that is currently being executed. When the execution of a command starts, the commandStarted() signal with the command's identifier is emitted. When the command is finished, the commandFinished() signal is emitted with the command's identifier and a bool that indicates whether the command finished with an error.

In some cases, you might want to execute a sequence of commands, e.g. if you want to connect and login to a FTP server. This is simply achieved:

    QFtp *ftp = new QFtp(parent);
    ftp->connectToHost("ftp.trolltech.com");
    ftp->login();

In this case two FTP commands have been scheduled. When the last scheduled command has finished, a done() signal is emitted with a bool argument that tells you whether the sequence finished with an error.

If an error occurs during the execution of one of the commands in a sequence of commands, all the pending commands (i.e. scheduled, but not yet executed commands) are cleared and no signals are emitted for them.

Some commands, e.g. list(), emit additional signals to report their results.

Example: If you want to download the INSTALL file from Trolltech's FTP server, you would write this:

    ftp->connectToHost("ftp.trolltech.com");  // id == 1
    ftp->login();                             // id == 2
    ftp->cd("qt");                            // id == 3
    ftp->get("INSTALL");                      // id == 4
    ftp->close();                             // id == 5

For this example the following sequence of signals is emitted (with small variations, depending on network traffic, etc.):

    start(1)
    stateChanged(HostLookup)
    stateChanged(Connecting)
    stateChanged(Connected)
    finished(1, false)

    start(2)
    stateChanged(LoggedIn)
    finished(2, false)

    start(3)
    finished(3, false)

    start(4)
    dataTransferProgress(0, 3798)
    dataTransferProgress(2896, 3798)
    readyRead()
    dataTransferProgress(3798, 3798)
    readyRead()
    finished(4, false)

    start(5)
    stateChanged(Closing)
    stateChanged(Unconnected)
    finished(5, false)

    done(false)

The dataTransferProgress() signal in the above example is useful if you want to show a progressbar to inform the user about the progress of the download. The readyRead() signal tells you that there is data ready to be read. The amount of data can be queried then with the bytesAvailable() function and it can be read with the read() or readAll() function.

If the login fails for the above example, the signals would look like this:

    start(1)
    stateChanged(HostLookup)
    stateChanged(Connecting)
    stateChanged(Connected)
    finished(1, false)

    start(2)
    finished(2, true)

    done(true)

You can then get details about the error with the error() and errorString() functions.

For file transfer, QFtp can use both active or passive mode, and it uses passive file transfer mode by default; see the documentation for setTransferMode() for more details about this.

Call setProxy() to make QFtp connect via an FTP proxy server.

The functions currentId() and currentCommand() provide more information about the currently executing command.

The functions hasPendingCommands() and clearPendingCommands() allow you to query and clear the list of pending commands.

If you are an experienced network programmer and want to have complete control you can use rawCommand() to execute arbitrary FTP commands.

Warning:
The current version of QFtp doesn't fully support non-Unix FTP servers. We hope to fix this in a future version of Qt.
See also:
QHttp, {FTP Example}

Definition at line 39 of file qftp.h.

Public Types

enum  State
enum  Error
enum  Command
enum  TransferMode
enum  TransferType

Public Slots

void abort ()

Signals

void stateChanged (int)
void listInfo (const QUrlInfo &)
void readyRead ()
void dataTransferProgress (qint64, qint64)
void rawCommandReply (int, const QString &)
void commandStarted (int)
void commandFinished (int, bool)
void done (bool)

Public Member Functions

 QFtp (QObject *parent=0)
virtual ~QFtp ()
int setProxy (const QString &host, quint16 port)
int connectToHost (const QString &host, quint16 port=21)
int login (const QString &user=QString(), const QString &password=QString())
int close ()
int setTransferMode (TransferMode mode)
int list (const QString &dir=QString())
int cd (const QString &dir)
int get (const QString &file, QIODevice *dev=0, TransferType type=Binary)
int put (const QByteArray &data, const QString &file, TransferType type=Binary)
int put (QIODevice *dev, const QString &file, TransferType type=Binary)
int remove (const QString &file)
int mkdir (const QString &dir)
int rmdir (const QString &dir)
int rename (const QString &oldname, const QString &newname)
int rawCommand (const QString &command)
qint64 bytesAvailable () const
qint64 read (char *data, qint64 maxlen)
QByteArray readAll ()
int currentId () const
QIODevicecurrentDevice () const
Command currentCommand () const
bool hasPendingCommands () const
void clearPendingCommands ()
State state () const
Error error () const
QString errorString () const

Private Member Functions

 Q_PRIVATE_SLOT (d_func(), void _q_startNextCommand()) Q_PRIVATE_SLOT(d_func()
void _q_piFinished (const QString &)) Q_PRIVATE_SLOT(d_func()
void void _q_piError (int, const QString &)) Q_PRIVATE_SLOT(d_func()
void void void _q_piConnectState (int)) Q_PRIVATE_SLOT(d_func()


Member Enumeration Documentation

enum QFtp::State

This enum defines the connection state:

Unconnected There is no connection to the host. HostLookup A host name lookup is in progress. Connecting An attempt to connect to the host is in progress. Connected Connection to the host has been achieved. LoggedIn Connection and user login have been achieved. Closing The connection is closing down, but it is not yet closed. (The state will be Unconnected when the connection is closed.)

See also:
stateChanged() state()

Definition at line 47 of file qftp.h.

00047                {
00048         Unconnected,
00049         HostLookup,
00050         Connecting,
00051         Connected,
00052         LoggedIn,
00053         Closing
00054     };

enum QFtp::Error

This enum identifies the error that occurred.

NoError No error occurred. HostNotFound The host name lookup failed. ConnectionRefused The server refused the connection. NotConnected Tried to send a command, but there is no connection to a server. UnknownError An error other than those specified above occurred.

See also:
error()

Definition at line 55 of file qftp.h.

00055                {
00056         NoError,
00057         UnknownError,
00058         HostNotFound,
00059         ConnectionRefused,
00060         NotConnected
00061     };

enum QFtp::Command

This enum is used as the return value for the currentCommand() function. This allows you to perform specific actions for particular commands, e.g. in a FTP client, you might want to clear the directory view when a list() command is started; in this case you can simply check in the slot connected to the start() signal if the currentCommand() is List.

None No command is being executed. SetTransferMode set the transfer mode. SetProxy switch proxying on or off. ConnectToHost connectToHost() is being executed. Login login() is being executed. Close close() is being executed. List list() is being executed. Cd cd() is being executed. Get get() is being executed. Put put() is being executed. Remove remove() is being executed. Mkdir mkdir() is being executed. Rmdir rmdir() is being executed. Rename rename() is being executed. RawCommand rawCommand() is being executed.

See also:
currentCommand()

Definition at line 62 of file qftp.h.

00062                  {
00063         None,
00064         SetTransferMode,
00065         SetProxy,
00066         ConnectToHost,
00067         Login,
00068         Close,
00069         List,
00070         Cd,
00071         Get,
00072         Put,
00073         Remove,
00074         Mkdir,
00075         Rmdir,
00076         Rename,
00077         RawCommand
00078     };

enum QFtp::TransferMode

FTP works with two socket connections; one for commands and another for transmitting data. While the command connection is always initiated by the client, the second connection can be initiated by either the client or the server.

This enum defines whether the client (Passive mode) or the server (Active mode) should set up the data connection.

Passive The client connects to the server to transmit its data.

Active The server connects to the client to transmit its data.

Definition at line 79 of file qftp.h.

00079                       {
00080         Active,
00081         Passive
00082     };

enum QFtp::TransferType

This enum identifies the data transfer type used with get and put commands.

Binary The data will be transferred in Binary mode.

Ascii The data will be transferred in Ascii mode and new line characters will be converted to the local format.

Definition at line 83 of file qftp.h.

00083                       {
00084         Binary,
00085         Ascii
00086     };


Constructor & Destructor Documentation

QFtp::QFtp ( QObject parent = 0  )  [explicit]

Constructs a QFtp object with the given parent.

Definition at line 1361 of file qftp.cpp.

References _q_piConnectState(), _q_piError(), _q_piFinished(), QObject::connect(), d, dataTransferProgress(), error(), listInfo(), readyRead(), SIGNAL, and SLOT.

01362     : QObject(*new QFtpPrivate, parent)
01363 {
01364     Q_D(QFtp);
01365     d->errorString = tr("Unknown error");
01366 
01367     connect(&d->pi, SIGNAL(connectState(int)),
01368             SLOT(_q_piConnectState(int)));
01369     connect(&d->pi, SIGNAL(finished(QString)),
01370             SLOT(_q_piFinished(QString)));
01371     connect(&d->pi, SIGNAL(error(int,QString)),
01372             SLOT(_q_piError(int,QString)));
01373     connect(&d->pi, SIGNAL(rawFtpReply(int,QString)),
01374             SLOT(_q_piFtpReply(int,QString)));
01375 
01376     connect(&d->pi.dtp, SIGNAL(readyRead()),
01377             SIGNAL(readyRead()));
01378     connect(&d->pi.dtp, SIGNAL(dataTransferProgress(qint64,qint64)),
01379             SIGNAL(dataTransferProgress(qint64,qint64)));
01380     connect(&d->pi.dtp, SIGNAL(listInfo(QUrlInfo)),
01381             SIGNAL(listInfo(QUrlInfo)));
01382 }

Here is the call graph for this function:

QFtp::~QFtp (  )  [virtual]

Destructor.

Definition at line 2357 of file qftp.cpp.

References abort(), and close().

02358 {
02359     abort();
02360     close();
02361 }

Here is the call graph for this function:


Member Function Documentation

int QFtp::setProxy ( const QString host,
quint16  port 
)

Enables use of the FTP proxy on host host and port port. Calling this function with host empty disables proxying.

QFtp does not support FTP-over-HTTP proxy servers. Use QHttp for this.

Definition at line 1701 of file qftp.cpp.

References QString::number(), and SetProxy.

01702 {
01703     QStringList args;
01704     args << host << QString::number(port);
01705     return d_func()->addCommand(new QFtpCommand(SetProxy, args));
01706 }

Here is the call graph for this function:

int QFtp::connectToHost ( const QString host,
quint16  port = 21 
)

Connects to the FTP server host using port port.

The stateChanged() signal is emitted when the state of the connecting process changes, e.g. to HostLookup, then Connecting, then Connected.

The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by commandStarted() and commandFinished().

When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.

See also:
stateChanged() commandStarted() commandFinished()

Definition at line 1624 of file qftp.cpp.

References ConnectToHost, and QString::number().

Referenced by FtpWindow::connectOrDisconnect().

01625 {
01626     d_func()->pi.transferConnectionExtended = true;
01627     QStringList cmds;
01628     cmds << host;
01629     cmds << QString::number((uint)port);
01630     return d_func()->addCommand(new QFtpCommand(ConnectToHost, cmds));
01631 }

Here is the call graph for this function:

int QFtp::login ( const QString user = QString(),
const QString password = QString() 
)

Logs in to the FTP server with the username user and the password password.

The stateChanged() signal is emitted when the state of the connecting process changes, e.g. to LoggedIn.

The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by commandStarted() and commandFinished().

When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.

See also:
commandStarted() commandFinished()

Definition at line 1651 of file qftp.cpp.

References QString::isNull(), and Login.

Referenced by FtpWindow::connectOrDisconnect().

01652 {
01653     QStringList cmds;
01654     cmds << (QLatin1String("USER ") + (user.isNull() ? QLatin1String("anonymous") : user) + QLatin1String("\r\n"));
01655     cmds << (QLatin1String("PASS ") + (password.isNull() ? QLatin1String("anonymous@") : password) + QLatin1String("\r\n"));
01656     return d_func()->addCommand(new QFtpCommand(Login, cmds));
01657 }

Here is the call graph for this function:

int QFtp::close (  ) 

Closes the connection to the FTP server.

The stateChanged() signal is emitted when the state of the connecting process changes, e.g. to Closing, then Unconnected.

The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by commandStarted() and commandFinished().

When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.

See also:
stateChanged() commandStarted() commandFinished()

Definition at line 1677 of file qftp.cpp.

References Close.

Referenced by ~QFtp().

01678 {
01679     return d_func()->addCommand(new QFtpCommand(Close, QStringList(QLatin1String("QUIT\r\n"))));
01680 }

int QFtp::setTransferMode ( TransferMode  mode  ) 

Sets the current FTP transfer mode to mode. The default is QFtp::Passive.

See also:
QFtp::TransferMode

Definition at line 1687 of file qftp.cpp.

References SetTransferMode.

01688 {
01689     d_func()->pi.transferConnectionExtended = true;
01690     d_func()->transferMode = mode;
01691     return d_func()->addCommand(new QFtpCommand(SetTransferMode, QStringList()));
01692 }

int QFtp::list ( const QString dir = QString()  ) 

Lists the contents of directory dir on the FTP server. If dir is empty, it lists the contents of the current directory.

The listInfo() signal is emitted for each directory entry found.

The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by commandStarted() and commandFinished().

When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.

See also:
listInfo() commandStarted() commandFinished()

Definition at line 1725 of file qftp.cpp.

References QString::isEmpty(), and Passive.

Referenced by FtpWindow::cdToParent(), FtpWindow::connectOrDisconnect(), and FtpWindow::processItem().

01726 {
01727     QStringList cmds;
01728     cmds << QLatin1String("TYPE A\r\n");
01729     cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n");
01730     if (dir.isEmpty())
01731         cmds << QLatin1String("LIST\r\n");
01732     else
01733         cmds << (QLatin1String("LIST ") + dir + QLatin1String("\r\n"));
01734     return d_func()->addCommand(new QFtpCommand(List, cmds));
01735 }

Here is the call graph for this function:

int QFtp::cd ( const QString dir  ) 

Changes the working directory of the server to dir.

The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by commandStarted() and commandFinished().

When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.

See also:
commandStarted() commandFinished()

Definition at line 1751 of file qftp.cpp.

References Cd.

Referenced by FtpWindow::cdToParent(), and FtpWindow::processItem().

01752 {
01753     return d_func()->addCommand(new QFtpCommand(Cd, QStringList(QLatin1String("CWD ") + dir + QLatin1String("\r\n"))));
01754 }

int QFtp::get ( const QString file,
QIODevice dev = 0,
TransferType  type = Binary 
)

Downloads the file file from the server.

If dev is 0, then the readyRead() signal is emitted when there is data available to read. You can then read the data with the read() or readAll() functions.

If dev is not 0, the data is written directly to the device dev. Make sure that the dev pointer is valid for the duration of the operation (it is safe to delete it when the commandFinished() signal is emitted). In this case the readyRead() signal is not emitted and you cannot read data with the read() or readAll() functions.

If you don't read the data immediately it becomes available, i.e. when the readyRead() signal is emitted, it is still available until the next command is started.

For example, if you want to present the data to the user as soon as there is something available, connect to the readyRead() signal and read the data immediately. On the other hand, if you only want to work with the complete data, you can connect to the commandFinished() signal and read the data when the get() command is finished.

The data is transferred as Binary or Ascii depending on the value of type.

The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by commandStarted() and commandFinished().

When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.

See also:
readyRead() dataTransferProgress() commandStarted() commandFinished()

Definition at line 1796 of file qftp.cpp.

References Binary, Get, and Passive.

Referenced by FtpWindow::downloadFile().

01797 {
01798     QStringList cmds;
01799     cmds << QLatin1String("SIZE ") + file + QLatin1String("\r\n");
01800     if (type == Binary)
01801         cmds << QLatin1String("TYPE I\r\n");
01802     else
01803         cmds << QLatin1String("TYPE A\r\n");
01804     cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n");
01805     cmds << QLatin1String("RETR ") + file + QLatin1String("\r\n");
01806     return d_func()->addCommand(new QFtpCommand(Get, cmds, dev));
01807 }

int QFtp::put ( const QByteArray data,
const QString file,
TransferType  type = Binary 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Writes a copy of the given data to the file called file on the server. The progress of the upload is reported by the dataTransferProgress() signal.

The data is transferred as Binary or Ascii depending on the value of type.

The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by commandStarted() and commandFinished().

When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.

Since this function takes a copy of the data, you can discard your own copy when this function returns.

See also:
dataTransferProgress() commandStarted() commandFinished()

Definition at line 1833 of file qftp.cpp.

References Binary, data, QString::number(), Passive, and Put.

01834 {
01835     QStringList cmds;
01836     if (type == Binary)
01837         cmds << QLatin1String("TYPE I\r\n");
01838     else
01839         cmds << QLatin1String("TYPE A\r\n");
01840     cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n");
01841     cmds << QLatin1String("ALLO ") + QString::number(data.size()) + QLatin1String("\r\n");
01842     cmds << QLatin1String("STOR ") + file + QLatin1String("\r\n");
01843     return d_func()->addCommand(new QFtpCommand(Put, cmds, data));
01844 }

Here is the call graph for this function:

int QFtp::put ( QIODevice dev,
const QString file,
TransferType  type = Binary 
)

Reads the data from the IO device dev, and writes it to the file called file on the server. The data is read in chunks from the IO device, so this overload allows you to transmit large amounts of data without the need to read all the data into memory at once.

The data is transferred as Binary or Ascii depending on the value of type.

Make sure that the dev pointer is valid for the duration of the operation (it is safe to delete it when the commandFinished() is emitted).

Definition at line 1860 of file qftp.cpp.

References Binary, QIODevice::isSequential(), QString::number(), Passive, Put, and QIODevice::size().

01861 {
01862     QStringList cmds;
01863     if (type == Binary)
01864         cmds << QLatin1String("TYPE I\r\n");
01865     else
01866         cmds << QLatin1String("TYPE A\r\n");
01867     cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n");
01868     if (!dev->isSequential())
01869         cmds << QLatin1String("ALLO ") + QString::number(dev->size()) + QLatin1String("\r\n");
01870     cmds << QLatin1String("STOR ") + file + QLatin1String("\r\n");
01871     return d_func()->addCommand(new QFtpCommand(Put, cmds, dev));
01872 }

Here is the call graph for this function:

int QFtp::remove ( const QString file  ) 

Deletes the file called file from the server.

The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by commandStarted() and commandFinished().

When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.

See also:
commandStarted() commandFinished()

Definition at line 1888 of file qftp.cpp.

References Remove.

01889 {
01890     return d_func()->addCommand(new QFtpCommand(Remove, QStringList(QLatin1String("DELE ") + file + QLatin1String("\r\n"))));
01891 }

int QFtp::mkdir ( const QString dir  ) 

Creates a directory called dir on the server.

The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by commandStarted() and commandFinished().

When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.

See also:
commandStarted() commandFinished()

Definition at line 1907 of file qftp.cpp.

References Mkdir.

01908 {
01909     return d_func()->addCommand(new QFtpCommand(Mkdir, QStringList(QLatin1String("MKD ") + dir + QLatin1String("\r\n"))));
01910 }

int QFtp::rmdir ( const QString dir  ) 

Removes the directory called dir from the server.

The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by commandStarted() and commandFinished().

When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.

See also:
commandStarted() commandFinished()

Definition at line 1926 of file qftp.cpp.

References Rmdir.

01927 {
01928     return d_func()->addCommand(new QFtpCommand(Rmdir, QStringList(QLatin1String("RMD ") + dir + QLatin1String("\r\n"))));
01929 }

int QFtp::rename ( const QString oldname,
const QString newname 
)

Renames the file called oldname to newname on the server.

The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by commandStarted() and commandFinished().

When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.

See also:
commandStarted() commandFinished()

Definition at line 1945 of file qftp.cpp.

References Rename.

01946 {
01947     QStringList cmds;
01948     cmds << QLatin1String("RNFR ") + oldname + QLatin1String("\r\n");
01949     cmds << QLatin1String("RNTO ") + newname + QLatin1String("\r\n");
01950     return d_func()->addCommand(new QFtpCommand(Rename, cmds));
01951 }

int QFtp::rawCommand ( const QString command  ) 

Sends the raw FTP command command to the FTP server. This is useful for low-level FTP access. If the operation you wish to perform has an equivalent QFtp function, we recommend using the function instead of raw FTP commands since the functions are easier and safer.

The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by commandStarted() and commandFinished().

When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.

See also:
rawCommandReply() commandStarted() commandFinished()

Definition at line 1971 of file qftp.cpp.

References RawCommand, and QString::trimmed().

01972 {
01973     QString cmd = command.trimmed() + QLatin1String("\r\n");
01974     return d_func()->addCommand(new QFtpCommand(RawCommand, QStringList(cmd)));
01975 }

Here is the call graph for this function:

qint64 QFtp::bytesAvailable (  )  const

Returns the number of bytes that can be read from the data socket at the moment.

See also:
get() readyRead() read() readAll()

Definition at line 1983 of file qftp.cpp.

01984 {
01985     return d_func()->pi.dtp.bytesAvailable();
01986 }

qint64 QFtp::read ( char *  data,
qint64  maxlen 
)

Reads maxlen bytes from the data socket into data and returns the number of bytes read. Returns -1 if an error occurred.

See also:
get() readyRead() bytesAvailable() readAll()

Definition at line 1999 of file qftp.cpp.

02000 {
02001     return d_func()->pi.dtp.read(data, maxlen);
02002 }

QByteArray QFtp::readAll (  ) 

Reads all the bytes available from the data socket and returns them.

See also:
get() readyRead() bytesAvailable() read()

Definition at line 2010 of file qftp.cpp.

02011 {
02012     return d_func()->pi.dtp.readAll();
02013 }

int QFtp::currentId (  )  const

Returns the identifier of the FTP command that is being executed or 0 if there is no command being executed.

See also:
currentCommand()

Definition at line 2059 of file qftp.cpp.

02060 {
02061     if (d_func()->pending.isEmpty())
02062         return 0;
02063     return d_func()->pending.first()->id;
02064 }

QIODevice * QFtp::currentDevice (  )  const

Returns the QIODevice pointer that is used by the FTP command to read data from or store data to. If there is no current FTP command being executed or if the command does not use an IO device, this function returns 0.

This function can be used to delete the QIODevice in the slot connected to the commandFinished() signal.

See also:
get() put()

Definition at line 2089 of file qftp.cpp.

References c.

02090 {
02091     if (d_func()->pending.isEmpty())
02092         return 0;
02093     QFtpCommand *c = d_func()->pending.first();
02094     if (c->is_ba)
02095         return 0;
02096     return c->data.dev;
02097 }

QFtp::Command QFtp::currentCommand (  )  const

Returns the command type of the FTP command being executed or None if there is no command being executed.

See also:
currentId()

Definition at line 2072 of file qftp.cpp.

References None.

Referenced by FtpWindow::ftpCommandFinished().

02073 {
02074     if (d_func()->pending.isEmpty())
02075         return None;
02076     return d_func()->pending.first()->command;
02077 }

bool QFtp::hasPendingCommands (  )  const

Returns true if there are any commands scheduled that have not yet been executed; otherwise returns false.

The command that is being executed is not considered as a scheduled command.

See also:
clearPendingCommands() currentId() currentCommand()

Definition at line 2108 of file qftp.cpp.

02109 {
02110     return d_func()->pending.count() > 1;
02111 }

void QFtp::clearPendingCommands (  ) 

Deletes all pending commands from the list of scheduled commands. This does not affect the command that is being executed. If you want to stop this this as well, use abort().

See also:
hasPendingCommands() abort()

Definition at line 2120 of file qftp.cpp.

Referenced by abort().

02121 {
02122     // delete all entires except the first one
02123     while (d_func()->pending.count() > 1)
02124         delete d_func()->pending.takeLast();
02125 }

QFtp::State QFtp::state (  )  const

Returns the current state of the object. When the state changes, the stateChanged() signal is emitted.

See also:
State stateChanged()

Definition at line 2133 of file qftp.cpp.

02134 {
02135     return d_func()->state;
02136 }

QFtp::Error QFtp::error (  )  const

Returns the last error that occurred. This is useful to find out what went wrong when receiving a commandFinished() or a done() signal with the error argument set to true.

If you start a new command, the error status is reset to NoError.

Definition at line 2145 of file qftp.cpp.

Referenced by QFtp().

02146 {
02147     return d_func()->error;
02148 }

QString QFtp::errorString (  )  const

Returns a human-readable description of the last error that occurred. This is useful for presenting a error message to the user when receiving a commandFinished() or a done() signal with the error argument set to true.

The error string is often (but not always) the reply from the server, so it is not always possible to translate the string. If the message comes from Qt, the string has already passed through tr().

Definition at line 2161 of file qftp.cpp.

02162 {
02163     return d_func()->errorString;
02164 }

void QFtp::abort (  )  [slot]

Aborts the current command and deletes all scheduled commands.

If there is an unfinished command (i.e. a command for which the commandStarted() signal has been emitted, but for which the commandFinished() signal has not been emitted), this function sends an ABORT command to the server. When the server replies that the command is aborted, the commandFinished() signal with the error argument set to true is emitted for the command. Due to timing issues, it is possible that the command had already finished before the abort request reached the server, in which case, the commandFinished() signal is emitted with the error argument set to false.

For all other commands that are affected by the abort(), no signals are emitted.

If you don't start further FTP commands directly after the abort(), there won't be any scheduled commands and the done() signal is emitted.

Warning:
Some FTP servers, for example the BSD FTP daemon (version 0.3), wrongly return a positive reply even when an abort has occurred. For these servers the commandFinished() signal has its error flag set to false, even though the command did not complete successfully.
See also:
clearPendingCommands()

Definition at line 2044 of file qftp.cpp.

References clearPendingCommands().

Referenced by FtpWindow::cancelDownload(), FtpWindow::connectOrDisconnect(), and ~QFtp().

02045 {
02046     if (d_func()->pending.isEmpty())
02047         return;
02048 
02049     clearPendingCommands();
02050     d_func()->pi.abort();
02051 }

void QFtp::stateChanged ( int  state  )  [signal]

This signal is emitted when the state of the connection changes. The argument state is the new state of the connection; it is one of the State values.

It is usually emitted in response to a connectToHost() or close() command, but it can also be emitted "spontaneously", e.g. when the server closes the connection unexpectedly.

See also:
connectToHost() close() state() State

void QFtp::listInfo ( const QUrlInfo i  )  [signal]

This signal is emitted for each directory entry the list() command finds. The details of the entry are stored in i.

See also:
list()

Referenced by QFtp().

void QFtp::readyRead (  )  [signal]

This signal is emitted in response to a get() command when there is new data to read.

If you specify a device as the second argument in the get() command, this signal is not emitted; instead the data is written directly to the device.

You can read the data with the readAll() or read() functions.

This signal is useful if you want to process the data in chunks as soon as it becomes available. If you are only interested in the complete data, just connect to the commandFinished() signal and read the data then instead.

See also:
get() read() readAll() bytesAvailable()

Referenced by QFtp().

void QFtp::dataTransferProgress ( qint64  done,
qint64  total 
) [signal]

This signal is emitted in response to a get() or put() request to indicate the current progress of the download or upload.

done is the amount of data that has already been transferred and total is the total amount of data to be read or written. It is possible that the QFtp class is not able to determine the total amount of data that should be transferred, in which case total is 0. (If you connect this signal to a QProgressBar, the progress bar shows a busy indicator if the total is 0).

Warning:
done and total are not necessarily the size in bytes, since for large files these values might need to be "scaled" to avoid overflow.
See also:
get(), put(), QProgressBar

Referenced by QFtp().

void QFtp::rawCommandReply ( int  replyCode,
const QString detail 
) [signal]

This signal is emitted in response to the rawCommand() function. replyCode is the 3 digit reply code and detail is the text that follows the reply code.

See also:
rawCommand()

void QFtp::commandStarted ( int  id  )  [signal]

This signal is emitted when processing the command identified by id starts.

See also:
commandFinished() done()

void QFtp::commandFinished ( int  id,
bool  error 
) [signal]

This signal is emitted when processing the command identified by id has finished. error is true if an error occurred during the processing; otherwise error is false.

See also:
commandStarted() done() error() errorString()

void QFtp::done ( bool  error  )  [signal]

This signal is emitted when the last pending command has finished; (it is emitted after the last command's commandFinished() signal). error is true if an error occurred during the processing; otherwise error is false.

See also:
commandFinished() error() errorString()

QFtp::Q_PRIVATE_SLOT ( d_func()  ,
void   _q_startNextCommand() 
) [private]

void QFtp::_q_piFinished ( const QString  )  [private]

Referenced by QFtp().

void void QFtp::_q_piError ( int  ,
const QString  
) [private]

Referenced by QFtp().

void void void QFtp::_q_piConnectState ( int   )  [private]

Referenced by QFtp().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 17:43:26 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1