|
QFtpCompat 1.0.0
Qt6-compatible async FTP client library
|
Asynchronous FTP client for Qt6. More...
#include <qftpcompat.h>
Public Types | |
| enum class | State { Unconnected , Connecting , Connected , LoggedIn , Closing } |
| High-level connection state. More... | |
| enum class | Error { NoError , HostNotFound , ConnectionRefused , NetworkTimeout , NetworkError , NotConnected , NotLoggedIn , LoginFailed , FileNotFound , PermissionDenied , ServerError , ParseError , LocalFileError , Aborted , TransferFailed , UnknownError , TlsHandshakeFailed , AuthTlsRejected } |
| Error codes set on the most recent failed command. More... | |
| enum class | TransferMode { Passive , Active } |
| FTP data channel mode. More... | |
| enum class | TransferType { Binary , Ascii } |
| FTP data representation type (RFC 959 §3.1.1). More... | |
| enum class | EncryptionMode |
| FTP encryption mode. \value None Plain FTP – default, fully backward-compatible. \value Explicit Explicit FTPS (AUTH TLS, port 21). \value Implicit Implicit FTPS (TLS from first byte, port 990). | |
Signals | |
| void | stateChanged (QFtpCompat::State newState) |
| Emitted when the connection state changes. | |
| void | commandStarted (int id) |
| Emitted when a queued command begins executing. | |
| void | commandFinished (int id, bool error) |
| Emitted when a command completes (successfully or with error). | |
| void | done (bool error) |
| Emitted when all queued commands have completed. | |
| void | listInfo (QFtpCompatDirEntry entry) |
| Emitted once per entry during a list() command. | |
| void | dataTransferProgress (qint64 bytesTransferred, qint64 bytesTotal) |
| Emitted periodically during data transfers. | |
| void | rawCommandReply (int code, QString detail) |
| Emitted for rawCommand() responses and pwd() results. | |
| void | sslErrors (const QList< QSslError > &errors) |
| Emitted when SSL/TLS errors occur. | |
Public Member Functions | |
| int | open (const QUrl &url, EncryptionMode mode=EncryptionMode::None) |
| Connects to the FTP server and logs in using the URL credentials. | |
| void | close () |
| Sends QUIT and closes the connection gracefully. | |
| void | abort () |
| Aborts the current data transfer and clears the command queue. | |
| int | get (const QUrl &url, QIODevice *dst, TransferType type=TransferType::Binary) |
Downloads a remote file into dst. | |
| int | get (const QUrl &url, QByteArray *dst, TransferType type=TransferType::Binary) |
Downloads a remote file into dst byte array. | |
| int | put (const QUrl &url, const QByteArray &data, TransferType type=TransferType::Binary) |
Uploads data to the remote path in url. | |
| int | put (const QUrl &url, QIODevice *src, TransferType type=TransferType::Binary) |
Uploads data from src to the remote path in url. | |
| int | list (const QUrl &url) |
| Requests a directory listing (LIST). | |
| int | mkdir (const QUrl &url) |
| Creates a directory on the server (MKD). | |
| int | rmdir (const QUrl &url) |
| Removes an empty directory on the server (RMD). | |
| int | remove (const QUrl &url) |
| Deletes a file on the server (DELE). | |
| int | rename (const QUrl &from, const QUrl &to) |
| Renames or moves a file on the server (RNFR + RNTO). | |
| int | cd (const QUrl &url) |
| Changes the current working directory (CWD). | |
| int | pwd () |
| Requests the current working directory path (PWD). | |
| int | rawCommand (const QString &command) |
| Sends an arbitrary FTP command on the control channel. | |
| State | state () const noexcept |
| Current connection state. | |
| Error | error () const noexcept |
| Error code set by the most recent failed command. | |
| QString | errorString () const noexcept |
| Verbose, human-readable description of the last error. | |
| int | currentId () const noexcept |
ID of the command currently being executed, or -1 if idle. | |
| bool | hasPendingCommands () const noexcept |
true if commands are waiting in the queue. | |
| void | setSslConfiguration (const QSslConfiguration &config) |
| Removes all pending (not yet started) commands from the queue. | |
| QSslConfiguration | sslConfiguration () const |
| Returns the current SSL configuration. | |
| void | ignoreSslErrors () |
| void | resetConnection () |
Asynchronous FTP client for Qt6.
Replaces the QFtp class that was removed from Qt5 and provides an identical asynchronous, command-queue-based API style.
Commands are queued and executed sequentially. Each method returns an integer ID that matches the id parameter in commandStarted and commandFinished.
Only Passive mode (PASV) is implemented. Active mode (PORT) is reserved for future implementation.
Both Binary (TYPE I) and Ascii (TYPE A) transfer types are supported at the protocol level. CRLF normalisation for Ascii transfers is not yet applied in the data stream; see the Ascii note in TransferType.
Must live on the thread that runs the Qt event loop (typically the main thread). Do not call any method from a different thread.
Definition at line 69 of file qftpcompat.h.
|
strong |
Error codes set on the most recent failed command.
| Enumerator | |
|---|---|
| NoError | No error since the last successful command. |
| HostNotFound | DNS resolution failed. |
| ConnectionRefused | Server actively refused the TCP connection. |
| NetworkTimeout | No activity within the inactivity timeout. |
| NetworkError | Generic socket error. |
| NotConnected | Command issued without an active connection. |
| NotLoggedIn | Command requires authentication. |
| LoginFailed | USER/PASS rejected by the server. |
| FileNotFound | Server returned 550 for a file operation. |
| PermissionDenied | Server returned 553 / 550 permission error. |
| ServerError | Unexpected server response code. |
| ParseError | Failed to parse a server response (PASV, LIST). |
| LocalFileError | Could not open or write to the local file/device. |
| Aborted | Operation cancelled by abort(). |
| TransferFailed | Data channel closed before transfer completed. |
| UnknownError | Catch-all for unclassified errors. |
| TlsHandshakeFailed | TLS handshake failed on control or data channel. |
| AuthTlsRejected | Server rejected the AUTH TLS command. |
Definition at line 93 of file qftpcompat.h.
|
strong |
High-level connection state.
Definition at line 81 of file qftpcompat.h.
|
strong |
FTP data channel mode.
Passive is currently implemented. Active (PORT) is reserved for a future release. | Enumerator | |
|---|---|
| Passive | PASV – client opens the data connection (firewall-friendly). |
| Active | PORT – server opens the data connection (not implemented). |
Definition at line 121 of file qftpcompat.h.
|
strong |
FTP data representation type (RFC 959 §3.1.1).
Ascii sends TYPE A to the server and therefore starts a valid ASCII-mode transfer at the protocol level, but the library currently does not perform CRLF normalisation on the data stream. If your use case requires proper line-ending translation, apply it to the data before passing it to put(), or after receiving it from get(). | Enumerator | |
|---|---|
| Binary | TYPE I – raw binary (8-bit) transfer. Fully implemented. |
| Ascii | TYPE A – text transfer. Protocol-level TYPE sent; no CRLF transform (TODO). |
Definition at line 137 of file qftpcompat.h.
| void QFtpCompat::abort | ( | ) |
Aborts the current data transfer and clears the command queue.
Sends ABOR on the control channel. Emits commandFinished with error = true for the aborted command.
Definition at line 127 of file qftpcompat.cpp.
| int QFtpCompat::cd | ( | const QUrl & | url | ) |
Changes the current working directory (CWD).
| url | URL whose path is the target directory. |
Definition at line 264 of file qftpcompat.cpp.
| void QFtpCompat::close | ( | ) |
Sends QUIT and closes the connection gracefully.
Remaining queued commands are cleared. Emits done(false) when the server acknowledges the QUIT.
Definition at line 117 of file qftpcompat.cpp.
|
signal |
Emitted when a command completes (successfully or with error).
| id | Command ID (matches the return value of the enqueue method). |
| error | true if the command failed; inspect errorString() for details. |
|
signal |
Emitted when a queued command begins executing.
| id | Command ID. |
|
signal |
Emitted periodically during data transfers.
| bytesTransferred | Bytes transferred so far. |
| bytesTotal | Total bytes to transfer, or -1 if unknown. |
|
signal |
Emitted when all queued commands have completed.
| error | true if the last command in the queue failed. |
| int QFtpCompat::get | ( | const QUrl & | url, |
| QByteArray * | dst, | ||
| TransferType | type = TransferType::Binary ) |
Downloads a remote file into dst byte array.
| url | Full URL of the remote file. |
| dst | Byte array to append downloaded data to. Not owned. |
| type | Transfer type. |
Definition at line 169 of file qftpcompat.cpp.
| int QFtpCompat::get | ( | const QUrl & | url, |
| QIODevice * | dst, | ||
| TransferType | type = TransferType::Binary ) |
Downloads a remote file into dst.
| url | Full URL of the remote file. |
| dst | Open writable QIODevice. Not owned by QFtpCompat. |
| type | Transfer type (Binary recommended for binary files). |
Definition at line 158 of file qftpcompat.cpp.
| void QFtpCompat::ignoreSslErrors | ( | ) |
Instructs both sockets to ignore all pending SSL errors. Call from a sslErrors handler to accept self-signed certificates.
Definition at line 111 of file qftpcompat.cpp.
| int QFtpCompat::list | ( | const QUrl & | url | ) |
Requests a directory listing (LIST).
Each parsed entry is emitted via listInfo before commandFinished is emitted.
| url | URL whose path is the directory to list. Use the root or an empty path to list the current directory. |
Definition at line 218 of file qftpcompat.cpp.
|
signal |
Emitted once per entry during a list() command.
| entry | Parsed directory entry. |
| int QFtpCompat::mkdir | ( | const QUrl & | url | ) |
Creates a directory on the server (MKD).
| url | URL whose path is the directory to create. |
Definition at line 227 of file qftpcompat.cpp.
| int QFtpCompat::open | ( | const QUrl & | url, |
| EncryptionMode | mode = EncryptionMode::None ) |
Connects to the FTP server and logs in using the URL credentials.
The url must contain at minimum a host. Port defaults to 21. User defaults to "anonymous", password to "anonymous\@".
Credentials can be embedded in the URL string or set via QUrl::setUserName() / QUrl::setPassword() – both forms are equivalent since the implementation reads url.userName() and url.password() regardless of how the QUrl was constructed:
| url | FTP URL carrying at minimum a host name. |
Connect and log in.
| url | Server URL (scheme, host, port, user, password). |
| mode | Encryption mode. Default: EncryptionMode::None (plain FTP – backward-compatible). |
Definition at line 89 of file qftpcompat.cpp.
| int QFtpCompat::put | ( | const QUrl & | url, |
| const QByteArray & | data, | ||
| TransferType | type = TransferType::Binary ) |
Uploads data to the remote path in url.
| url | Full URL of the remote destination. |
| data | Data to upload. Copied internally. |
| type | Transfer type. |
Definition at line 186 of file qftpcompat.cpp.
| int QFtpCompat::put | ( | const QUrl & | url, |
| QIODevice * | src, | ||
| TransferType | type = TransferType::Binary ) |
Uploads data from src to the remote path in url.
| url | Full URL of the remote destination. |
| src | Open readable QIODevice. Not owned by QFtpCompat. |
| type | Transfer type. |
src into an internal buffer at command start. For streaming large files, consider pre-loading the data and using the QByteArray overload instead. Definition at line 202 of file qftpcompat.cpp.
| int QFtpCompat::pwd | ( | ) |
Requests the current working directory path (PWD).
The path is returned via rawCommandReply with code 257.
Definition at line 273 of file qftpcompat.cpp.
| int QFtpCompat::rawCommand | ( | const QString & | command | ) |
Sends an arbitrary FTP command on the control channel.
The server response is emitted via rawCommandReply.
| command | Raw FTP command string (without CRLF). |
Definition at line 281 of file qftpcompat.cpp.
|
signal |
Emitted for rawCommand() responses and pwd() results.
| code | FTP response code (e.g. 257 for PWD). |
| detail | Human-readable message text from the server. |
| int QFtpCompat::remove | ( | const QUrl & | url | ) |
Deletes a file on the server (DELE).
| url | URL whose path is the file to delete. |
Definition at line 245 of file qftpcompat.cpp.
| int QFtpCompat::rename | ( | const QUrl & | from, |
| const QUrl & | to ) |
Renames or moves a file on the server (RNFR + RNTO).
| from | URL whose path is the current file location. |
| to | URL whose path is the new file location. |
Definition at line 254 of file qftpcompat.cpp.
| void QFtpCompat::resetConnection | ( | ) |
Hard-resets the FTP session: clears queue, aborts TCP sockets, sets state to Unconnected without sending QUIT. Safe to call in any state.
Definition at line 300 of file qftpcompat.cpp.
| int QFtpCompat::rmdir | ( | const QUrl & | url | ) |
Removes an empty directory on the server (RMD).
| url | URL whose path is the directory to remove. |
Definition at line 236 of file qftpcompat.cpp.
| void QFtpCompat::setSslConfiguration | ( | const QSslConfiguration & | config | ) |
Removes all pending (not yet started) commands from the queue.
The currently executing command is not affected.
Sets the SSL configuration used for both control and data channels.
Call before open() to customise certificates, peer-verify mode, etc. The default configuration uses QSslSocket::VerifyPeer.
Definition at line 99 of file qftpcompat.cpp.
|
signal |
Emitted when SSL/TLS errors occur.
To accept self-signed certificates (common on embedded servers):
|
signal |
Emitted when the connection state changes.
| newState | New connection state. |