qt怎么把windows自带的ftp

qt怎么把windows自带的ftp,第1张

配置好服务器之后,便可以使用QT或者其他工具实现文件上传和下载了。
关键代码如下:
void ftp_upload::upload() { ftp = new QFtp(this); ftp->connectToHost("192168050",21); //连接到服务器,填写你的ip地址,这里默认端口号为21 ftp->login("test","testpasswd"); //登录,填写响应的用户名和密码 //windows自带的ftp服务器,客户端上传文件到服务器 QFile uploadFile = new QFile("D:/2014txt");//要上传到服务器的的文件位置:D盘下的2014txt文档,该文档存在于客户端 QString des = "2014_uploadToServertxt";//ftp服务器“收到”客户端上传的文档位置:物理路径根目录下的文档2014_uploadtxt uploadFile->open(QIODevice::ReadWrite); ftp->put(uploadFile,des); //windows自带的ftp服务器,从服务器下载文件到客户端 QFile download = new QFile("D:/downloadFromServertxt"); download->open(QIODevice::ReadWrite); ftp->get("downloadtxt",download);//把服务器物理路径根目录下的downloadtxt下载到本地D盘根目录 }

用QFtp应该可以做到吧, 摘自Qt的帮助文档, QFtp::get()时将次二哥参数设置为0,之后收到 readyRead()后可以通过read()或readAll()读取到内存里。
int QFtp::get ( const QString & file, QIODevice dev = 0, TransferType type = Binary )
If dev is 0, then the readyRead() signal is emitted when there is data available to read You can then read the data with the read() or readAll() functions


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/13506141.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-08-21
下一篇 2023-08-21

发表评论

登录后才能评论

评论列表(0条)

保存