Downloading file from FTP server
-
Hi
You can still use the QFtp class or use external lib like CURl.If you do not require many ftp functions/integration, you could just use curl or wget command line tool and simply
fire it via QProcess. -
In order to have an http server service based on Qt I'm using Poco
https://pocoproject.org/ It is very great!
It has got an ftp component too. -
@Qjay
Hi
Both wget and CURL runs on windows and linux.
CURL also run macOS. (CURL even runs in DOS ;)
https://curl.haxx.se/download.html
https://eternallybored.org/misc/wget/You can just include the tools (.exe) in apps folder.
They are standalone cmd line, requiring no install and will
only add 10 MB to the installer size.Anyway, not knowing what you really need, maybe sing POCO or QFTP/ something else integrated is better.
Running a cmdline tool with QProcess is just very easy if all you need is to download a predefined file. -
Curl has a C API https://curl.haxx.se/libcurl/ with bindings in other languages like C++ (http://www.curlpp.org/) so you can build it and link to it on basically all platforms Qt supports.
Having said that, if you have an ftp url and just want to download it,
QNetworkAccessManager
is more than enough to achieve your target -
@VRonin said in Downloading file from FTP server:
QNetworkAccessManager
Hi
I could not find a sample for download but this uploads to ftp
https://evileg.com/en/post/255/Please update if you find downloading from ftp sample :)
-
you can use qftp class derectly in qt4
if you are using qt5 ,you can get this class from github -
@mrjj said in Downloading file from FTP server:
Please update if you find downloading from ftp sample
It's just a normal get request, as it was http:
#include <QCoreApplication> #include <QNetworkAccessManager> #include <QNetworkReply> #include <QNetworkRequest> int main(int argc, char *argv[]) { QCoreApplication a(argc,argv); QNetworkAccessManager netMan; QNetworkReply* const repl = netMan.get(QNetworkRequest(QUrl::fromUserInput(R"**(ftp://131.225.104.13/linux/.snapshot/NDMP_AUTO_SNAPSHOT3210/fermi/contrib/obsolete/video/nvidia/5328/NVIDIA.5328.README.txt)**"))); QObject::connect(repl,&QNetworkReply::readyRead,[repl]()->void{ qDebug().noquote() << repl->readAll(); }); QObject::connect(repl,QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error),[repl]()->void{ qDebug() << "Error: " + repl->errorString(); }); return a.exec(); }
@James-Haitching said in Downloading file from FTP server:
you can get [QFtp] from github
No, that module is outdated and not maintained. Never use old code when you have a chance of using cryptography. If you want to do more advanced stuff (like getting directory listing) then use libcurl/curlpp
-
@VRonin said in Downloading file from FTP server:
QNetworkAccessManager netMan;
QNetworkReply* const repl = netMan.get(QNetworkRequest(QUrl::fromUserInput(R"(ftp://131.225.104.13/linux/.snapshot/NDMP_AUTO_SNAPSHOT3210/fermi/contrib/obsolete/video/nvidia/5328/NVIDIA.5328.README.txt)")));
QObject::connect(repl,&QNetworkReply::readyRead,repl->void{
qDebug().noquote() << repl->readAll();
});
QObject::connect(repl,QOverloadQNetworkReply::NetworkError::of(&QNetworkReply::error),repl->void{
qDebug() << "Error: " + repl->errorString();
});suppose i have to pass login details too , how can i do it ? FTP server is password protected
-
#include <QCoreApplication> #include <QNetworkAccessManager> #include <QNetworkReply> #include <QNetworkRequest> int main(int argc, char *argv[]) { QCoreApplication a(argc,argv); QNetworkAccessManager netMan; QNetworkReply* const repl = netMan.get(QNetworkRequest(QUrl::fromUserInput(R"**(ftp://131.225.104.13/linux/.snapshot/NDMP_AUTO_SNAPSHOT3210/fermi/contrib/obsolete/video/nvidia/5328/NVIDIA.5328.README.txt)**"))); QObject::connect(repl,&QNetworkReply::readyRead,[repl]()->void{ qDebug().noquote() << repl->readAll(); }); QObject::connect(repl,QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error),[repl]()->void{ qDebug() << "Error: " + repl->errorString(); }); QObject::connect(repl,&QNetworkReply::finished,repl,&QNetworkReply::deleteLater); QObject::connect(&netMan,&QNetworkAccessManager::authenticationRequired,repl,[repl](QNetworkReply *reply, QAuthenticator *authenticator)->void{ if(reply!=repl) return; aAuthenticator->setUser("MyUserName"); aAuthenticator->setPassword("MyPassword"); }); return a.exec(); }