简体   繁体   中英

connect to FTP server and access to files

I'm trying to write a simple code so that I can get files from a FTP server. My code is shown below, but I even cannot connect to that server (the code shown below has no errors). I've searched a lot and tried others codes, with no success. Is there any problem with my code? Any help will be appreciated.

#include "mainwindow.h"
#include <QApplication>
#include <QUrl>
#include <QNetworkAccessManager>
#include <iostream>
#include <QNetworkRequest>

using namespace std;
int main(int argc, char* argv[])
{
    QApplication a(argc, argv);

    QNetworkAccessManager qnam;
    QUrl url("ftp://radaqco.com/somefile.txt");

    url.setHost(QString("host"));
    url.setUserName(QString("user"));
    url.setPassword(QString("pswd"));
    url.setPort(21);
    QNetworkRequest nRequest(url);
    qnam.get(nRequest);

    return a.exec();
}

get of QNetworkAccessManager is asynchronous. It will return immediately. You need to wait for the readyRead signal, and have a slot connected for it.

C++ enthusiast kid from India :) You can make a batch file to connect to ftp and open your C++ executable then using file handling read the downloaded file and finally put them on screen !

@echo off
echo connecting ftp server...
ftp files.mayukhpankaj.com
//will be asked for username and password

cd uploads
put logs.txt

save it as .bat file ! and then simple file reading c++ program !

#include<fstream.h>
using namespace std;

int main()
{
char n[20];
ifstream f1(logs);
f1>>n;
while(f1)'
cout<<n<<"";

return 0;
Hi guys i am Mayukh Pankaj 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM