简体   繁体   中英

QT C++ - FTP Upload

I've got a problem with programming an easy FTP-Upload in QT. I am currently using QT 5.5 and the QFtp Class is no longer available. So I used the code that is working in my Visual C++ project.

  1. Image: Code from Visual C++来自 Visual C++ 的代码

  2. Image: Code in QT图片:QT 中的代码

  3. Image: Build Error in QT图片:QT 中的构建错误

Is there a way I can fix this problem? Is it possible to get QFtp working in QT 5.5?

(string fileToUpload is the file path)

(string fileName is the name of the file on the remote machine when it is uploaded)

Thanks in advance!

As stated in the Qt 5.4 documentation, there are add-ons that provide FTP and HTTP streams:

https://forum.qt.io/topic/23904/qtftp-and-qthttp-compatibility-add-ons-for-qhttp-and-qftp-classes-in-qt-5

However, I suggest you start using QNetworkManager to do your FTP & HTTP access. Its interface is more complex (essentially all requests are handled asynchronuously) but when you get the hang of it, it's not so difficult.

Your compilation error is related to conversion of const char* to const wchar_t* . If you are satisfied with FtpPutFileW you can just convert file name to wchar_t* . That can be done using Qt QString : QString::toWCharArray(wchar_t * array) to convert the string to wchar_t array (this function does not append null character) or using direct cast:

reinterpret_cast<const wchar_t *>(qstring.utf16())

Also it possible to use various approaches to conversion of std::string to wchar_t* .

If you need just FTP put operation the QNetworkManager has such function. However, QNetworkManager has limited support for low level FTP: https://stackoverflow.com/a/32568786/4023446

So, for other low level FTP commands it is possible to install manually Qt FTP .

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