📄 qftp.cpp
字号:
This signal is emitted in response to a get() or put() request to indicate the current progress of the download or upload. \a done is the amount of data that has already been transferred and \a 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 \a total is 0. (If you connect this signal to a QProgressBar, the progress bar shows a busy indicator if the total is 0). \warning \a done and \a total are not necessarily the size in bytes, since for large files these values might need to be "scaled" to avoid overflow. \sa get(), put(), QProgressBar*//*! \fn void QFtp::rawCommandReply(int replyCode, const QString &detail); This signal is emitted in response to the rawCommand() function. \a replyCode is the 3 digit reply code and \a detail is the text that follows the reply code. \sa rawCommand()*//*! Connects to the FTP server \a host using port \a port. The stateChanged() signal is emitted when the state of the connecting process changes, e.g. to \c HostLookup, then \c Connecting, then \c 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. \sa stateChanged() commandStarted() commandFinished()*/int QFtp::connectToHost(const QString &host, quint16 port){ d_func()->pi.transferConnectionExtended = true; QStringList cmds; cmds << host; cmds << QString::number((uint)port); return d_func()->addCommand(new QFtpCommand(ConnectToHost, cmds));}/*! Logs in to the FTP server with the username \a user and the password \a password. The stateChanged() signal is emitted when the state of the connecting process changes, e.g. to \c 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. \sa commandStarted() commandFinished()*/int QFtp::login(const QString &user, const QString &password){ QStringList cmds; cmds << (QLatin1String("USER ") + (user.isNull() ? QLatin1String("anonymous") : user) + QLatin1String("\r\n")); cmds << (QLatin1String("PASS ") + (password.isNull() ? QLatin1String("anonymous@") : password) + QLatin1String("\r\n")); return d_func()->addCommand(new QFtpCommand(Login, cmds));}/*! Closes the connection to the FTP server. The stateChanged() signal is emitted when the state of the connecting process changes, e.g. to \c Closing, then \c 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. \sa stateChanged() commandStarted() commandFinished()*/int QFtp::close(){ return d_func()->addCommand(new QFtpCommand(Close, QStringList(QLatin1String("QUIT\r\n"))));}/*! Sets the current FTP transfer mode to \a mode. The default is QFtp::Passive. \sa QFtp::TransferMode*/int QFtp::setTransferMode(TransferMode mode){ d_func()->pi.transferConnectionExtended = true; d_func()->transferMode = mode; return d_func()->addCommand(new QFtpCommand(SetTransferMode, QStringList()));}/*! Enables use of the FTP proxy on host \a host and port \a port. Calling this function with \a host empty disables proxying. QFtp does not support FTP-over-HTTP proxy servers. Use QHttp for this.*/int QFtp::setProxy(const QString &host, quint16 port){ QStringList args; args << host << QString::number(port); return d_func()->addCommand(new QFtpCommand(SetProxy, args));}/*! Lists the contents of directory \a dir on the FTP server. If \a 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. \sa listInfo() commandStarted() commandFinished()*/int QFtp::list(const QString &dir){ QStringList cmds; cmds << QLatin1String("TYPE A\r\n"); cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n"); if (dir.isEmpty()) cmds << QLatin1String("LIST\r\n"); else cmds << (QLatin1String("LIST ") + dir + QLatin1String("\r\n")); return d_func()->addCommand(new QFtpCommand(List, cmds));}/*! Changes the working directory of the server to \a 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. \sa commandStarted() commandFinished()*/int QFtp::cd(const QString &dir){ return d_func()->addCommand(new QFtpCommand(Cd, QStringList(QLatin1String("CWD ") + dir + QLatin1String("\r\n"))));}/*! Downloads the file \a file from the server. If \a 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 \a dev is not 0, the data is written directly to the device \a dev. Make sure that the \a 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 \e 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 \a 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. \sa readyRead() dataTransferProgress() commandStarted() commandFinished()*/int QFtp::get(const QString &file, QIODevice *dev, TransferType type){ QStringList cmds; cmds << QLatin1String("SIZE ") + file + QLatin1String("\r\n"); if (type == Binary) cmds << QLatin1String("TYPE I\r\n"); else cmds << QLatin1String("TYPE A\r\n"); cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n"); cmds << QLatin1String("RETR ") + file + QLatin1String("\r\n"); return d_func()->addCommand(new QFtpCommand(Get, cmds, dev));}/*! \overload Writes a copy of the given \a data to the file called \a 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 \a 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 \a data, you can discard your own copy when this function returns. \sa dataTransferProgress() commandStarted() commandFinished()*/int QFtp::put(const QByteArray &data, const QString &file, TransferType type){ QStringList cmds; if (type == Binary) cmds << QLatin1String("TYPE I\r\n"); else cmds << QLatin1String("TYPE A\r\n"); cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n"); cmds << QLatin1String("ALLO ") + QString::number(data.size()) + QLatin1String("\r\n"); cmds << QLatin1String("STOR ") + file + QLatin1String("\r\n"); return d_func()->addCommand(new QFtpCommand(Put, cmds, data));}/*! Reads the data from the IO device \a dev, and writes it to the file called \a 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 \a type. Make sure that the \a dev pointer is valid for the duration of the operation (it is safe to delete it when the commandFinished() is emitted).*/int QFtp::put(QIODevice *dev, const QString &file, TransferType type){ QStringList cmds; if (type == Binary) cmds << QLatin1String("TYPE I\r\n"); else cmds << QLatin1String("TYPE A\r\n"); cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n"); if (!dev->isSequential()) cmds << QLatin1String("ALLO ") + QString::number(dev->size()) + QLatin1String("\r\n"); cmds << QLatin1String("STOR ") + file + QLatin1String("\r\n"); return d_func()->addCommand(new QFtpCommand(Put, cmds, dev));}/*! Deletes the file called \a 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. \sa commandStarted() commandFinished()*/int QFtp::remove(const QString &file){ return d_func()->addCommand(new QFtpCommand(Remove, QStringList(QLatin1String("DELE ") + file + QLatin1String("\r\n"))));}/*! Creates a directory called \a 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. \sa commandStarted() commandFinished()*/int QFtp::mkdir(const QString &dir){ return d_func()->addCommand(new QFtpCommand(Mkdir, QStringList(QLatin1String("MKD ") + dir + QLatin1String("\r\n"))));}/*! Removes the directory called \a 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. \sa commandStarted() commandFinished()*/int QFtp::rmdir(const QString &dir){ return d_func()->addCommand(new QFtpCommand(Rmdir, QStringList(QLatin1String("RMD ") + dir + QLatin1String("\r\n"))));}/*! Renames the file called \a oldname to \a 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. \sa commandStarted() commandFinished()*/int QFtp::rename(const QString &oldname, const QString &newname){ QStringList cmds; cmds << QLatin1String("RNFR ") + oldname + QLatin1String("\r\n"); cmds << QLatin1String("RNTO ") + newname + QLatin1String("\r\n"); return d_func()->addCommand(new QFtpCommand(Rename, cmds));}/*! Sends the raw FTP command \a 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. \sa rawCommandReply() commandStarted() commandFinished()*/int QFtp::rawCommand(const QString &command){ QString cmd = command.trimmed() + QLatin1String("\r\n"); return d_func()->addCommand(new QFtpCommand(RawCommand, QStringList(cmd)));}/*! Returns the number of bytes that can be read from the data socket at the moment. \sa get() readyRead() read() readAll()*/qint64 QFtp::by
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -