Unsolved Are we able to delete files on FTP server using QT?
-
I read an article that this was not supported by QNetworkAccessManager, but this was back in 2013. Has this changed at all in the last 8 years? When I try to issue a delete using QNetworkAccessManager::deleteResource, I get an error saying: "Protocol 'ftp' is unknown".
So I guess my question is... is there another way?
QUrl url; url.setHost(m_ftp_host); url.setPort(m_ftp_port); url.setUserName(m_ftp_username); url.setPassword(m_ftp_password); url.setScheme("ftp"); url.setPath(ftp_absolute_file_path); QNetworkAccessManager* manager = new QNetworkAccessManager(); const QNetworkRequest request(url); QNetworkReply* reply = manager->deleteResource(request); connect(reply, &QNetworkReply::errorOccurred, [=] { QString errorMessage = reply->errorString(); qDebug() << "Error: " << errorMessage; }); connect(manager, &QNetworkAccessManager::finished, this, &FileUploadWorker::onDeleteComplete);
-
@KidTrent said in Are we able to delete files on FTP server using QT?:
"Protocol 'ftp' is unknown".
Note: This feature is currently available for HTTP only, performing an HTTP DELETE request.
(from: https://doc.qt.io/qt-5/qnetworkaccessmanager.html#deleteResource)
-
@KidTrent
Currently HTTP, FTP and local file URLs are supported for uploading and downloading.
https://forum.qt.io/topic/127393/are-we-able-to-delete-files-on-ftp-server-using-qt
However, actual implementing is not clear to me atm. How Qt handles choice between active/passive ftp? I don't know.
From my experience, you should experiment with sending control words to the server - set user name and password and so on, then try custom request with control work, like "PASV" or "TYPE A" or "TYPE I" and then analyse replies.
Or, if you're willing to consider the learnings done by others, there is quite old library you can take a look at https://github.com/qt/qtftp
-
@artwaw said in Are we able to delete files on FTP server using QT?:
you can take a look at https://github.com/qt/qtftp
Qt FTP has been discontinued a long time ago.
QNAM dropped the FTP support by design and I don't see it getting it back.
There are plenty of well established libraries to handle ftp (like libcurl), you don't need to use an obsolete library with no support -
@VRonin said in Are we able to delete files on FTP server using QT?:
QNAM dropped the FTP support by design and I don't see it getting it back.
This page needs updating then... https://doc.qt.io/qt-5/qtnetwork-programming.html
-
@artwaw said in Are we able to delete files on FTP server using QT?:
This page needs updating then... https://doc.qt.io/qt-5/qtnetwork-programming.html
Why? FTP is supported, but AFAIK you can't delete stuff on the FTP server with a
QNetworkRequest
(using the FTP protocol) -
@Pl45m4 I don't know why but apparently @VRonin knows it has been dropped:
@VRonin said in Are we able to delete files on FTP server using QT?:
QNAM dropped the FTP support by design and I don't see it getting it back.
-
My bad. You can do very basic operations (upload and download) using FTP and QNAM. I don't consider this to be "supprting" ftp as even the most simple of operations (listing files) is not supported.
When the FTP module was dropped from Qt Network I considered it as the sign I should look to an external library for that -
IIRC this example (https://doc.qt.io/qt-5/qtnetwork-download-example.html) works (or worked at least with 5.15) using FTP.
I'm a bit confused :)Edit:
@VRonin said in Are we able to delete files on FTP server using QT?:
My bad. You can do very basic operations (upload and download) using FTP and QNAM. I don't consider this to be "supprting" ftp as even the most simple of operations (listing files) is not supported.
Not confused anymore ;-)
-
@VRonin Thank you for clarifying!