This class provides two different interfaces: one is the TQNetworkProtocol interface that allows you to use FTP through the TQUrlOperator abstraction. The other is a direct interface to FTP that gives you lower-level access to the FTP protocol for finer control. Using the direct interface you can also execute arbitrary FTP commands.
This code will only work if the TQFtp class is registered; to register the class, you must call tqInitNetworkProtocols() before using a TQUrlOperator with TQFtp.
The rest of this descrption describes the direct interface to FTP.
.PP
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.
.PP
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().
.PP
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.
.PP
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:
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.
.PP
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.
.PP
Some commands, e.g. list(), emit additional signals to report their results.
.PP
Example: If you want to download the INSTALL file from Trolltech's FTP server, you would write this:
.PP
.nf
.br
ftp->connectToHost( "ftp.trolltech.com" ); // id == 1
.br
ftp->login(); // id == 2
.br
ftp->cd( "qt" ); // id == 3
.br
ftp->get( "INSTALL" ); // id == 4
.br
ftp->close(); // id == 5
.br
.fi
.PP
For this example the following sequence of signals is emitted (with small variations, depending on network traffic, etc.):
.PP
.nf
.br
start( 1 )
.br
stateChanged( HostLookup )
.br
stateChanged( Connecting )
.br
stateChanged( Connected )
.br
finished( 1, FALSE )
.br
.br
start( 2 )
.br
stateChanged( LoggedIn )
.br
finished( 2, FALSE )
.br
.br
start( 3 )
.br
finished( 3, FALSE )
.br
.br
start( 4 )
.br
dataTransferProgress( 0, 3798 )
.br
dataTransferProgress( 2896, 3798 )
.br
readyRead()
.br
dataTransferProgress( 3798, 3798 )
.br
readyRead()
.br
finished( 4, FALSE )
.br
.br
start( 5 )
.br
stateChanged( Closing )
.br
stateChanged( Unconnected )
.br
finished( 5, FALSE )
.br
.br
done( FALSE )
.br
.fi
.PP
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 readBlock() or readAll() function.
.PP
If the login fails for the above example, the signals would look like this:
.PP
.nf
.br
start( 1 )
.br
stateChanged( HostLookup )
.br
stateChanged( Connecting )
.br
stateChanged( Connected )
.br
finished( 1, FALSE )
.br
.br
start( 2 )
.br
finished( 2, TRUE )
.br
.br
done( TRUE )
.br
.fi
.PP
You can then get details about the error with the error() and errorString() functions.
.PP
The functions currentId() and currentCommand() provide more information about the currently executing command.
.PP
The functions hasPendingCommands() and clearPendingCommands() allow you to query and clear the list of pending commands.
The safest and easiest way to use the FTP protocol is to use TQUrlOperator() or the FTP commands described above. If you are an experienced network programmer and want to have complete control you can use rawCommand() to execute arbitrary FTP commands.
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.
Aborts the current command and deletes all scheduled commands.
.PP
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 \fCABORT\fR command to the server. When the server replies that the command is aborted, the commandFinished() signal with the \fCerror\fR argument set to \fCTRUE\fR 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 \fCerror\fR argument set to \fCFALSE\fR.
.PP
For all other commands that are affected by the abort(), no signals are emitted.
.PP
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.
.PP
\fBWarning:\fR 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 \fCFALSE\fR, even though the command did not complete successfully.
Changes the working directory of the server to \fIdir\fR.
.PP
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().
.PP
When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.
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().
The stateChanged() signal is emitted when the state of the connecting process changes, e.g. to Closing, then Unconnected.
.PP
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().
.PP
When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.
.PP
See also stateChanged(), commandStarted(), and commandFinished().
This signal is emitted when processing the command identified by \fIid\fR has finished. \fIerror\fR is TRUE if an error occurred during the processing; otherwise \fIerror\fR is FALSE.
.PP
See also commandStarted(), done(), error(), and errorString().
Connects to the FTP server \fIhost\fR using port \fIport\fR.
.PP
The stateChanged() signal is emitted when the state of the connecting process changes, e.g. to HostLookup, then Connecting, then Connected.
.PP
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().
.PP
When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.
.PP
See also stateChanged(), commandStarted(), and commandFinished().
Returns the TQIODevice 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.
\fIdone\fR is the amount of data that has already been transferred and \fItotal\fR is the total amount of data to be read or written. It is possible that the TQFtp class is not able to determine the total amount of data that should be transferred, in which case \fItotal\fR is 0. (If you connect this signal to a TQProgressBar, the progress bar shows a busy indicator if the total is 0).
\fBWarning:\fR \fIdone\fR and \fItotal\fR are not necessarily the size in bytes, since for large files these values might need to be" scaled" to avoid overflow.
This signal is emitted when the last pending command has finished; (it is emitted after the last command's commandFinished() signal). \fIerror\fR is TRUE if an error occurred during the processing; otherwise \fIerror\fR is FALSE.
.PP
See also commandFinished(), error(), and errorString().
Returns the last error that occurred. This is useful to find out what when wrong when receiving a commandFinished() or a done() signal with the \fCerror\fR argument set to \fCTRUE\fR.
.PP
If you start a new command, the error status is reset to NoError.
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 \fCerror\fR argument set to \fCTRUE\fR.
.PP
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().
If \fIdev\fR is 0, then the readyRead() signal is emitted when there is data available to read. You can then read the data with the readBlock() or readAll() functions.
.PP
If \fIdev\fR is not 0, the data is written directly to the device \fIdev\fR. Make sure that the \fIdev\fR 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 \fInot\fR emitted and you cannot read data with the readBlock() or readAll() functions.
.PP
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.
.PP
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.
.PP
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().
.PP
When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.
.PP
See also readyRead(), dataTransferProgress(), commandStarted(), and commandFinished().
Lists the contents of directory \fIdir\fR on the FTP server. If \fIdir\fR is empty, it lists the contents of the current directory.
.PP
The listInfo() signal is emitted for each directory entry found.
.PP
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().
.PP
When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.
.PP
See also listInfo(), commandStarted(), and commandFinished().
Logs in to the FTP server with the username \fIuser\fR and the password \fIpassword\fR.
.PP
The stateChanged() signal is emitted when the state of the connecting process changes, e.g. to LoggedIn.
.PP
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().
.PP
When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.
Creates a directory called \fIdir\fR on the server.
.PP
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().
.PP
When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.
Reads the data from the IO device \fIdev\fR, and writes it to the file called \fIfile\fR 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.
.PP
Make sure that the \fIdev\fR pointer is valid for the duration of the operation (it is safe to delete it when the commandFinished() is emitted).
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Writes the data \fIdata\fR to the file called \fIfile\fR on the server. The progress of the upload is reported by the dataTransferProgress() signal.
.PP
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().
.PP
When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.
.PP
See also dataTransferProgress(), commandStarted(), and commandFinished().
Sends the raw FTP command \fIcommand\fR to the FTP server. This is useful for low-level FTP access. If the operation you wish to perform has an equivalent TQFtp 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().
.PP
When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.
.PP
See also rawCommandReply(), commandStarted(), and commandFinished().
This signal is emitted in response to the rawCommand() function. \fIreplyCode\fR is the 3 digit reply code and \fIdetail\fR is the text that follows the reply code.
This signal is emitted in response to a get() command when there is new data to read.
.PP
If you specify a device as the second argument in the get() command, this signal is \fInot\fR emitted; instead the data is written directly to the device.
.PP
You can read the data with the readAll() or readBlock() functions.
.PP
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.
.PP
See also get(), readBlock(), readAll(), and bytesAvailable().
Deletes the file called \fIfile\fR from the server.
.PP
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().
.PP
When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.
Renames the file called \fIoldname\fR to \fInewname\fR on the server.
.PP
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().
.PP
When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.
Removes the directory called \fIdir\fR from the server.
.PP
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().
.PP
When the command is started the commandStarted() signal is emitted. When it is finished the commandFinished() signal is emitted.
This signal is emitted when the state of the connection changes. The argument \fIstate\fR is the new state of the connection; it is one of the State values.
.PP
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.
.PP
See also connectToHost(), close(), state(), and State.