1

I need to upload an image file on server using ssh2 protocol on port 22. SSH2 protocol with QNetworkAccessManger is not popular on Google either. Here is my code.

QUrl uploadUrl("ssh2://192.168.10.227/var/www/html/img/"+mImgFile);

    uploadUrl.setUserName("xxxxxx");
    uploadUrl.setPassword("xxxxxx");
    uploadUrl.setPort(22);

    qDebug() << uploadUrl.toString();

    QNetworkRequest uploadReq(uploadUrl);

    mReply = mNetworkManager->put(uploadReq, &file);

    connect(mReply, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(uploadProgress(qint64, qint64)));

With URL-scheme as "ssh2" or "sftp" or "ssh2.sftp"; it outputs that Protocol is unknown. And the reason i used strange-looking "ssh2.sftp", is here(just a little php code to view).

I want to know whether ssh2 can be used with qnetworkaccessmanager at all? If yes, what is the correct URL-format to upload an image file?

Jatin
  • 276
  • 6
  • 12

1 Answers1

2

There is no SSH support in Qt, for example see Howto implement SFTP with Qt/QNetworkAccessManager (C++) and How to easily establish an SSH connection in Qt?

The list of supported URL schemes in QNetworkAccessManager can be obtained by QNetworkAccessManager::supportedSchemes() that is ("ftp", "file", "qrc", "http", "https", "data") in default Qt releases (https is supported only if external OpenSSL library is found, since it is also not supplied with Qt).

So, it is still needed to use external C library libssh2 to work with SSH2 protocol using native sockets.

I found here that there was some old Qt extension LibQxt with Qt SSH support. However, it is no longer maintained.

Community
  • 1
  • 1
Orest Hera
  • 6,706
  • 2
  • 21
  • 35
  • @Jatin I'm glad that it was helpful. You have a linker error. If you use an external library it should be explicitly added to the project (e.g., .pro file) for proper linking. If you have troubles with this then it makes sense to open a new question with clear problem description (integration of QxtSshClient and libssh2 wih Qt project) with steps you have done and observed issues. In that way more people will be involved in solving some specific problem. – Orest Hera Sep 25 '15 at 11:45
  • Your answer was certainly helpful:) I put in some more effort with QxtSshClient class downloaded from [here](https://github.com/mnutt/libqxt/blob/master/src/network/qxtsshclient.cpp) and libssh2 from your above link. But now I am getting a list of *undefined reference to `libssh2_channel_process_startup'* such errors, even when the file "libssh2.h" has been included. I do not know what else needs to be done with such libraries. Any more help please? Sorry, I misspelled your name in previous comment. So, deleted it. – Jatin Sep 25 '15 at 12:09
  • Yes. The file is included in .pro file as well. Even then, i get this error. Anyways, happy with your help. – Jatin Sep 25 '15 at 12:17
  • @Jatin I mean not just include "libssh2.h" in .pro. In C/C++ build consists of two main stages: compilation of source files by compiler to object files and linkage of compiled object file by linker. It is enough for compiler to include "libssh2.h", however linker that collects all binaries into one executable also should know that you want to link some external library binary. The variable `LIB` is used in .pro files for both required steps for linker: (1) add path to search external binary and (2) link library. See http://doc.qt.io/qt-5/third-party-libraries.html – Orest Hera Sep 25 '15 at 12:26
  • I went through the suggested link. It was fine till INCLUDEPATH usage. But got stuck on using LIBS as the downloaded "libssh2" does not contain any library files (.so for my Fedora 22 OS). How to go now? – Jatin Sep 28 '15 at 06:43
  • @Jatin What did you download? Probably it is just a source code package. In that case it should be compiled as any external 3rd party library. After building it on linux there are by default static and dynamic library files: libssh2.a, libssh2.so (symbolic link to libssh2.so.1.0.1). – Orest Hera Sep 28 '15 at 07:06
  • Build it successfully!! You were right. It was just a source code package. Got library files after building it. Now it's upto me to use it in my code. You actually led me from nowhere, great help :-) – Jatin Sep 28 '15 at 11:51
  • @Jatin I'm glad I was able to help. It would be also useful to have some feedback from you regarding your experience of integrating old `QxtSshClient` with current Qt versions to know whether it is still possible or you have to use `libssh2` with native sockets. Someone may look for that. – Orest Hera Sep 28 '15 at 12:57
  • Right. Once I integrate successfully, i'll post the answer. And congratulations to you, your reputation crossed 1000.! – Jatin Sep 29 '15 at 05:21