📄 qftp.3qt
字号:
'\" t.TH QFtp 3qt "9 December 2002" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQFtp \- Implementation of the FTP protocol.SH SYNOPSIS\fC#include <qftp.h>\fR.PPInherits QNetworkProtocol..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQFtp\fR ()".br.ti -1c.BI "\fBQFtp\fR ( QObject * parent, const char * name = 0 )".br.ti -1c.BI "virtual \fB~QFtp\fR ()".br.ti -1c.BI "enum \fBState\fR { Unconnected, HostLookup, Connecting, Connected, LoggedIn, Closing }".br.ti -1c.BI "enum \fBError\fR { NoError, UnknownError, HostNotFound, ConnectionRefused, NotConnected }".br.ti -1c.BI "enum \fBCommand\fR { None, ConnectToHost, Login, Close, List, Cd, Get, Put, Remove, Mkdir, Rmdir, Rename, RawCommand }".br.ti -1c.BI "int \fBconnectToHost\fR ( const QString & host, Q_UINT16 port = 21 )".br.ti -1c.BI "int \fBlogin\fR ( const QString & user = QString::null, const QString & password = QString::null )".br.ti -1c.BI "int \fBclose\fR ()".br.ti -1c.BI "int \fBlist\fR ( const QString & dir = QString::null )".br.ti -1c.BI "int \fBcd\fR ( const QString & dir )".br.ti -1c.BI "int \fBget\fR ( const QString & file, QIODevice * dev = 0 )".br.ti -1c.BI "int \fBput\fR ( const QByteArray & data, const QString & file )".br.ti -1c.BI "int \fBput\fR ( QIODevice * dev, const QString & file )".br.ti -1c.BI "int \fBremove\fR ( const QString & file )".br.ti -1c.BI "int \fBmkdir\fR ( const QString & dir )".br.ti -1c.BI "int \fBrmdir\fR ( const QString & dir )".br.ti -1c.BI "int \fBrename\fR ( const QString & oldname, const QString & newname )".br.ti -1c.BI "int \fBrawCommand\fR ( const QString & command )".br.ti -1c.BI "Q_ULONG \fBbytesAvailable\fR () const".br.ti -1c.BI "Q_LONG \fBreadBlock\fR ( char * data, Q_ULONG maxlen )".br.ti -1c.BI "QByteArray \fBreadAll\fR ()".br.ti -1c.BI "int \fBcurrentId\fR () const".br.ti -1c.BI "QIODevice * \fBcurrentDevice\fR () const".br.ti -1c.BI "Command \fBcurrentCommand\fR () const".br.ti -1c.BI "bool \fBhasPendingCommands\fR () const".br.ti -1c.BI "void \fBclearPendingCommands\fR ()".br.ti -1c.BI "State \fBstate\fR () const".br.ti -1c.BI "Error \fBerror\fR () const".br.ti -1c.BI "QString \fBerrorString\fR () const".br.in -1c.SS "Public Slots".in +1c.ti -1c.BI "void \fBabort\fR ()".br.in -1c.SS "Signals".in +1c.ti -1c.BI "void \fBstateChanged\fR ( int state )".br.ti -1c.BI "void \fBlistInfo\fR ( const QUrlInfo & i )".br.ti -1c.BI "void \fBreadyRead\fR ()".br.ti -1c.BI "void \fBdataTransferProgress\fR ( int done, int total )".br.ti -1c.BI "void \fBrawCommandReply\fR ( int replyCode, const QString & detail )".br.ti -1c.BI "void \fBcommandStarted\fR ( int id )".br.ti -1c.BI "void \fBcommandFinished\fR ( int id, bool error )".br.ti -1c.BI "void \fBdone\fR ( bool error )".br.in -1c.SH DESCRIPTIONThe QFtp class provides an implementation of the FTP protocol..PPThis class provides two different interfaces: one is the QNetworkProtocol interface that allows you to use FTP through the QUrlOperator 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..PPDon't mix the two interfaces, since the behavior is not well-defined..PPIf you want to use QFtp with the QNetworkProtocol interface, you do not use it directly, but rather through a QUrlOperator, for example:.PP.nf.br QUrlOperator op( "ftp://ftp.trolltech.com" );.br op.listChildren(); // Asks the server to provide a directory listing.br.fi.PPThis code will only work if the QFtp class is registered; to register the class, you must call qInitNetworkProtocols() before using a QUrlOperator with QFtp..PPThe rest of this descrption describes the direct interface to FTP..PPThe 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..PPThe 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()..PPAll 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..PPIn 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:.PP.nf.br QFtp *ftp = new QFtp( this ); // this is an optional QObject parent.br ftp->connectToHost( "ftp.trolltech.com" );.br ftp->login();.br.fi.PPIn 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..PPIf 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..PPSome commands, e.g. list(), emit additional signals to report their results..PPExample: 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.PPFor 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.PPThe 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..PPIf 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.PPYou can then get details about the error with the error() and errorString() functions..PPThe functions currentId() and currentCommand() provide more information about the currently executing command..PPThe functions hasPendingCommands() and clearPendingCommands() allow you to query and clear the list of pending commands..PPThe safest and easiest way to use the FTP protocol is to use QUrlOperator() 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..PPSee also Qt Network Documentation, QNetworkProtocol, QUrlOperator, QHttp, and Input/Output and Networking..SS "Member Type Documentation".SH "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..TP\fCQFtp::None\fR - No command is being executed..TP\fCQFtp::ConnectToHost\fR - connectToHost() is being executed..TP\fCQFtp::Login\fR - login() is being executed..TP\fCQFtp::Close\fR - close() is being executed..TP\fCQFtp::List\fR - list() is being executed..TP\fCQFtp::Cd\fR - cd() is being executed..TP\fCQFtp::Get\fR - get() is being executed..TP\fCQFtp::Put\fR - put() is being executed..TP\fCQFtp::Remove\fR - remove() is being executed..TP\fCQFtp::Mkdir\fR - mkdir() is being executed..TP\fCQFtp::Rmdir\fR - rmdir() is being executed..TP\fCQFtp::Rename\fR - rename() is being executed..TP\fCQFtp::RawCommand\fR - rawCommand() is being executed..PPSee also currentCommand()..SH "QFtp::Error"This enum identifies the error that occurred.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -