[英]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. 我正在尝试编写一个简单的代码,以便可以从FTP服务器获取文件。 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. QNetworkAccessManager
get
是异步的。 It will return immediately. 它将立即返回。 You need to wait for the
readyRead
signal, and have a slot connected for it. 您需要等待
readyRead
信号,并为此连接一个插槽。
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 ! 来自印度的C ++狂热小子:)您可以制作一个批处理文件以连接到ftp并打开您的C ++可执行文件,然后使用文件处理功能读取下载的文件,最后将它们放在屏幕上!
@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 ! 将其另存为.bat文件! and then simple file reading c++ program !
然后简单的文件读取C ++程序!
#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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.