Home » U++ Library support » U++ MT-multithreading and servers » SSH package for U++ (A feature-rich ilbssh2 wrapper for Ultimate++)
| SSH package for U++ [message #48973] |
Tue, 14 November 2017 21:59  |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello guys,
I am officially announcing the release of "beta" version of SSH package.
Package is tested on Arch Linux (Kernel: 4.13, GCC 7.2) and Windows (7/10, MinGW 7.2/MSC 14 (2017))
SSH package for U++
--------------------
SSH package is a feautre-rich, flexible yet very easy to use libssh2 wrapper for Ultimate++.
It supports both console and GUI-based applications on POSIX-compliant operating systems and
MS Windows (tm).
Currently it is in beta (version 1) stage.
Classes:
--------------------
- Base (core) class -> Ssh
- Ssh session -----> SshSession
- Sftp subsystem -----> SFtp
- Ssh channel -----> SshChannel
- Scp channel -----> Scp
- Exec channel -----> SshExec
- Real-time interactive shell -----> SshShell
- X11 forwarding -----> SshShell (as operation mode)
- Tcp/IP and port forwarding -----> SshTunnel
- Known hosts manager -> SshHosts
Features and Highlights:
--------------------
- Ssh-derived classes have pick semantics, based on RAII principle, support RTTI, and allow
polymorphism (i.e. different classes can be stored in the same arrays, etc.) through a common
interface.
- Uses U++ memory allocators (Native allocators is also a compile-time option)
- Uses OpenSSL by default.
- Supports time-constrained, blocking and non-blocking operation modes.
- Supoorts multithreaded file transfers and remote command execution (exec), using worker threads.
- Supports 3rd-party network proxies. (Such as NetProxy)
- Supports known hosts verification mechanism.
- Supports password, public key, host-based, and keyboard-interactive authentication methods.
- Supports ssh-agents.
- Supports real-time interactive command line (shell) interface with both console and GUI integration (works on Windows and Posix-compliant OS'es)
- Supports multiple X11 connection forwarding.
- Supports Tcp/IP and port forwarding.
- Supports detailed (full) debug logging.
Todo:
--------------------
- Add more high level methods.
- Refactor Ssh (core) class.
- Improve documentation.
Reference examples:
-------------------
- SFtpGet: Demonstrates basic SFtp file download in blocking mode.
- SFtpGetNB: Demonstrates basic SFtp file download in non-blocking mode.
- SFtpGetMT: Demonstrates basic SFtp file download, using a worker thread.
- SFtpGUI: Demonstrates a basic SFtp browser with GUI (with upload, download, mkdir, rename, delete commands).
- SFtpMultiGetMT: Demonstrates SFtp dir listing and concurrent file transfers, using worker threads.
- SFtpConsumerGet: Demonstrates the usage of a consumer function for SFtp download in blocking mode.
- SFtpConsumerGetMT: Demonstrates the usage of a consumer function for SFtp download, using a worker thread.
- SshExec: Demonstrates basic Ssh remote command execution in blocking mode.
- SshExecNB: Demonstrates basic Ssh remote command execution in non-blocking mode.
- SshExecMT: Demonstrates basic Ssh remote command execution, using a worker thread.
- SshKeyboardAuth: Demonstrates basic Ssh interactive (challenge-response) authentication method in blocking mode.
- SshLoggingExample: Demonstrates the logging capabilities of SSH package.
- SshOverTor: Demonstrates a basic Ssh connection over TOR, using a third-party network proxy adapter.
- SshPolymorphismNB: Demonstrates the polymorphism capability of SSH channels in non-blocking mode.
- SshShell: Demonstrates a basic, real-time SSH shell console in blocking mode.
- SshShellNB: Demonstrates a basic, real-time SSH shell console in non-blocking mode.
- SshShellX11: Demonstrates a basic, real-time SSH shell console with multiple X11 forwarding.
- SshShellGUI: Demonstrates the basic GUI integration of SshShell class with multiple X11 forwarding, in non-blocking mode.
- SshTunnelExample: Demonstrates the basic SSH tunneling (as tunnel/server) in blocking mode.
Below you can find the latest package and the GIT address where you can always get the latest version.
GIT repo: https://github.com/ismail-yilmaz/upp-components/tree/master/ Core/SSH
Examples: https://github.com/ismail-yilmaz/upp-components/tree/master/ Examples
Older Version: https://github.com/ismail-yilmaz/upp-components/tree/master/ Attic/SSH
I appreciate bug reports, reviews, criticism, patches etc.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sat, 16 June 2018 19:05] Report message to a moderator
|
|
|
|
| Re: SSH package for U++ [message #48982 is a reply to message #48973] |
Fri, 17 November 2017 22:15   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello,
I am currenty writing a simple SFTP (GUI) browser example, which I will include in the package, and upload it to GIT repo.
In the meantime, for those who wonder how to do non-blocking operations with SFtp, here is a simple example (it is a real example which can be compiled.):
#include <Core/Core.h>
#include <SSH/SSH.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
// This example demonstrates (in non-blocking mode):
// 1) Reading the size of a file.
// 2) Reading the content of a file (into a String).
// 3) Reading the content of a directory as XML.
int CMD_GET = 0, CMD_LIST = 0, CMD_SIZE = 0;
const char *file = "/readme.txt";
SFtp::DirList ls;
Ssh::Trace();
SshSession session;
if(session.Timeout(30000).Connect("test.rebex.net", 22, "demo", "password")) {
Array<SFtp> sftps;
for(int i = 0; i < 3; i++) {
auto& sftp = sftps.Add(new SFtp(session));
sftp.NonBlocking();
switch(i) {
case 0: sftp.Get(file); CMD_GET = sftp.GetId(); break;
case 1: sftp.GetSize(file); CMD_SIZE = sftp.GetId(); break;
case 2: sftp.ListDir("/pub/example/", ls); CMD_LIST = sftp.GetId(); break;
default: NEVER();
}
}
while(!sftps.IsEmpty()) {
for(int i = 0 ; i < sftps.GetCount(); i++) {
SocketWaitEvent we;
auto& sftp = sftps[i];
sftp.AddTo(we);
we.Wait(10);
if(!sftp.Do()) {
if(sftp.IsError())
Cerr() << sftp.GetErrorDesc() << '\n';
else {
if(sftp.GetId() == CMD_GET) {
Cout() << sftp.GetResult();
}
else
if(sftp.GetId() == CMD_SIZE) {
Cout() << Format("Size of %s is %d bytes\n", file, sftp.GetResult());
}
else
if(sftp.GetId() == CMD_LIST) {
for(auto& e : ls)
Cout() << e.ToXml() << '\n';
}
}
sftps.Remove(i);
break;
}
}
}
}
else
Cerr() << session.GetErrorDesc();
}
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Fri, 17 November 2017 22:19] Report message to a moderator
|
|
|
|
|
|
|
|
| Re: SSH package for U++ [message #49000 is a reply to message #48973] |
Tue, 21 November 2017 00:38   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello,
SSH package & examples are updated.
Package gained 2 new examples. One is simple, other is relatively complex.
SshKeyboardAuth: Demonstrates SSH keyboard interactive (challange/response) authentication method.
SFtpMultiGet: Demonstrates download of multiple files simultaneously in SFTP non-blocking mode (non MT).
Bug reports, patches, criticism, suggestions, or any questions are always welcome.
You can always find the updated package and the address of its GIT repo in the first message of this topic.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Tue, 21 November 2017 00:39] Report message to a moderator
|
|
|
|
|
|
| Re: SSH package for U++ [message #49008 is a reply to message #48973] |
Fri, 24 November 2017 21:03   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello,
SSH package is updated.
New method:
bool SshSession::Connect(const String& url)
--------------------------------------------
Connects to a SSH2 server specified by the url. Returns true on success.
Syntax of the URL is as follows:
[ssh|scp|sftp|exec]://[user:password@]host[:port]
In time, the syntax will be improved (optional args will be added.)
Also a new example (SFtpMultiGetMT) is added to the examples.
This example downloads 4 files asynchronously, using worker threads, and is the multithreaded counterpart of SFtpMultiGetNB (non-blocking).
It also demonstrates the capabilities of the U++ AsyncWork worker threads.
Bug reports, patches, criticism, suggestions, or any questions are always welcome.
You can always find the updated package and the address of its GIT repo in the first message of this topic.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Fri, 24 November 2017 21:06] Report message to a moderator
|
|
|
|
|
|
| Re: SSH package for U++ [message #49014 is a reply to message #49013] |
Sun, 26 November 2017 09:59   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello Jan Marco,
Thank you very much for your comments and suggestions. 
I've tested swish and it does a decent job for sure.
However, I believe SSH package and swish do not fall under the same categories. Their scope and intended audience seems to be different.
From its website: "Swish is a plugin for Microsoft Windows Explorer that adds support for SFTP."
It is a decent plugin for Windows Explorer, it falls under applications/plugins category, if I may.
Naturally, it is limited to Windows platform, and as far as I can understand, it uses OpenSSL exclusively.
And it seems to be limited to SFTP subsystem.
On the other hand SSH package isn't an app or plugin written by U++. It is an easy to use SSH2 library (it covers full SSH2 ecosystem: Sftp, channels, exec, scp, shell, agents) for U++, and its intended audience is exclusively U++ developers.
SSH uses libssh2 under the hood. libssh2 is a widely used and extensively tested, multiplatform SSH2 library with BSD license. SSH package supports what libssh2 supports.
Therefore SSH package is not limited to windows. In fact, it isn't developed on windows. In theory SSH package can run on what U++ and libssh2 can run on and this includes, but not limited to, Linux and Windows.
Also, while SSH package uses OpenSSL by default, it is also possible to use it with WinCNG and GnuTLS. (Currently through a config file, in the near future via compiler flag.)
In fact there is nothing that prevents a developer to come up with a similar plugin to swish, using SSH pacakge.(Maybe it'll take a lot less time to develop one using SSH package, since the main purpose of SSH package is to let developers focus on other aspects of their apps.)
One major advantage (for commercial app developers) of SSH package over swish is that SSH package (and underlying libssh2) uses BSD license.
To sum up:
1) Swish offers good functionality, but the functionality it offers is mostly on application-level. Hence they should be implemented by the application developers (using SSH package).
2) Writing some example app similar to swish would be platform specific. Therefore I am writing a simple SFtpBrowser example, which will work on any platform that U++ supports. 
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sun, 26 November 2017 11:24] Report message to a moderator
|
|
|
|
|
|
| Re: SSH package for U++ [message #49029 is a reply to message #49027] |
Fri, 01 December 2017 12:33   |
alkema_jm
Messages: 25 Registered: November 2015
|
Promising Member |
|
|
Hello Oblivion ,
>Thank you very much for your comments and suggestions.
Thank you that you ask feedback
>I've tested swish and it does a decent job for sure.
I tried (/test) to compile Swish. At one point i could start it, but it crasht.
> However, I believe SSH package and swish do not fall under the same categories. Their scope and intended audience seems to be different.
Ok, I think in software components. I like the Windows Explorer integration of Swish only.
>From its website: "Swish is a plugin for Microsoft Windows Explorer that adds support for SFTP."
It is a decent plugin for Windows Explorer, it falls under applications/plugins category, if I may.
Yes, I like Microsoft Windows Explorer integration part of Swish.
>Naturally, it is limited to Windows platform, and as far as I can understand, it uses OpenSSL exclusively.
I don't like. "One size fits all". Some solutions (for example Microsoft Windows Explorer integration) can be better in specific (native) solutions.
>And it seems to be limited to SFTP subsystem.
The FileZilla engine 'uses' more protocols (storj) :

> On the other hand SSH package isn't an app or plugin written by U++. It is an easy to use SSH2 library (it covers full SSH2 ecosystem: Sftp, channels, exec, scp, shell, agents) for U++, and its intended audience is exclusively U++ developers.
I like the SSH2 econsystem very much
> SSH uses libssh2 under the hood. libssh2 is a widely used and extensively tested, multiplatform SSH2 library with BSD license. SSH package supports what libssh2 supports.
Ok, You limit SSH package to "libssh2"?
> Therefore SSH package is not limited to windows. In fact, it isn't developed on windows. In theory SSH package can run on what U++ and libssh2 can run on and this includes, but not limited to, Linux and Windows.
I think it is usefull to think in interfaces (and api) of software components. I separated the (General) FileZilla engine code. I will try to interface with libssh2 (SSH package). I haven't look in the libssh2 code if it is possible.
> Also, while SSH package uses OpenSSL by default, it is also possible to use it with WinCNG and GnuTLS. (Currently through a config file, in the near future via compiler flag.)
FileZilla uses GnuTLS.
> In fact there is nothing that prevents a developer to come up with a similar plugin to swish, using SSH pacakge.(Maybe it'll take a lot less time to develop one using SSH package, since the main purpose of SSH package is to let developers focus on other aspects of their apps.)
I like your SSH package very much, because it Works
> One major advantage (for commercial app developers) of SSH package over swish is that SSH package (and underlying libssh2) uses BSD license.
I am not a company. Licenses are not very interesting subject for me.
> To sum up:
>1) Swish offers good functionality, but the functionality it offers is mostly on application-level. Hence they should be implemented by the application developers (using SSH package).
Ok.
2) Writing some example app similar to swish would be platform specific. Therefore I am writing a simple SFtpBrowser example, which will work on any platform that U++ supports.
Ok, a simple example is alway usefull to see that it Works. I think that a more complex example als FileZilla is not difficult to migrate to Ultimate++.
Greetings Jan Marco
|
|
|
|
| Re: SSH package for U++ [message #49030 is a reply to message #49029] |
Fri, 01 December 2017 14:35   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello Jan Marco,
I really appreciate you feedback. Thank you very much!
Quote:The FileZilla engine 'uses' more protocols (storj) :
We already have HTTP(S)(HttpRequest class does that) and FTP(S). Have you looked at the FTP package that I wrote? ( https://www.ultimatepp.org/forums/index.php?t=msg&th=889 9&goto=43053&#msg_43053)
It covers FTP, and FTPS (FTP over explicit TLS/SSL). Check the video too. It shows what it is capable of: (https://vimeo.com/214530673)
The only protocol we seem to lack is StorJ, which is not really hard to implement. Maybe I should add it to my Todo list. 
Quote:Ok, a simple example is alway usefull to see that it Works. I think that a more complex example als FileZilla is not difficult to migrate to Ultimate++.
FTP class I mentioned above contains an example called FtpBrowser. That example will eventually evolve into a MultiBrowser (FTP(S)/SFtp/HTTP(S)) after I finalized the SSH package.
(In fact it contains a package called BrowserCtrl, which is meant to be a gui-frontend for filesystem-agnostic file browsers).
So while I'm not going to port filezilla to U++ (it'll need a lot of work), I'll come up with a simpler remote file browser demo. 
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Fri, 01 December 2017 14:39] Report message to a moderator
|
|
|
|
| Re: SSH package for U++ [message #49032 is a reply to message #49030] |
Sat, 02 December 2017 09:29   |
alkema_jm
Messages: 25 Registered: November 2015
|
Promising Member |
|
|
Hello Oblivion,
> We already have HTTP(S)(HttpRequest class does that) and FTP(S).
Ok.
> Have you looked at the FTP package that I wrote? ( https://www.ultimatepp.org/forums/index.php?t=msg&th=889 9&goto=43053&#msg_43053)
No, but I looked now.
>- Support for extending the functionality of Ftp class, using the low-level SendCommand() method.
I think that SendCommand has other meaning then the SendCommand of the FileZilla engine. FileZilla sends commands to the loaded executable Fzftp.exe. Fzftp.exe is derived from Putty project.
> It covers FTP, and FTPS (FTP over explicit TLS/SSL). Check the video too. It shows what it is capable of: (https://vimeo.com/214530673)
Seems good implementation. Video doesn't have sound/speech.
> FTP class I mentioned above contains an example called FtpBrowser. That example will eventually evolve into a MultiBrowser (FTP(S)/SFtp/HTTP(S)) after I finalized the SSH package. (In fact it contains a package called BrowserCtrl, which is meant to be a gui-frontend for filesystem-agnostic file browsers).
Ok. You implement what other (platforms) already have. I think it is better to implement something new, for example TOR integration. I put 'all' TOR code in 1 file (207329 lines of cpp code).
> The only protocol we seem to lack is StorJ, which is not really hard to implement. Maybe I should add it to my Todo list.
Oblivion, Is it possible to add t (for Tor) after protocol Info name, Like 'sftpt' for sftp over TOR network:

I don't know how to go to TOR implementation. Implement Libssh2 routines to the TOR implementation. I have not studie. Maybe put packets on TOR-socket?
> So while I'm not going to port filezilla to U++ (it'll need a lot of work), I'll come up with a simpler remote file browser demo.
I am trying to make a proof of concept of seperate Filezilla in three parts. GUI, engine and infrastructure code.
Greetings Jan Marco
|
|
|
|
| Re: SSH package for U++ [message #49033 is a reply to message #49032] |
Sat, 02 December 2017 10:44   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello Jan Marco,
Quote:I think that SendCommand has other meaning then the SendCommand of the FileZilla engine. FileZilla sends commands to the loaded executable Fzftp.exe. Fzftp.exe is derived from Putty project.
Sure, Ftp::SendCommand() is simply a convenient way to send control commands that aren't already covered by the FTP package.
Quote:Ok. You implement what other (platforms) already have.
Think of it this way: I am implementing what I think Ultimate++ lacks (and what I need in U++). After all, these packages are meant to be used in U++ applications.
By the way, recently I set up a GIT address where I upload 3rd party packages I wrote for U++. There are only several packages in the repo now but it will grow in time, once I clean up and publish the library I personally use: https://github.com/ismail-yilmaz/upp-components
Quote:I don't know how to go to TOR implementation. Implement Libssh2 routines to the TOR implementation. I have not studie. Maybe put packets on TOR-socket?
I have good news and (somewhat) bad news: TOR is on my todo list (with WEBDAV, OAuth2, etc...), but it isn't an easy-to-implement protocol.
However "in theory" (I didn't actually test it) it is possible to use it, without writing a whole TOR client.
There is a package called NetProxy (it is a Https/Socks4/4a/5 proxy adapter for U++) which, again, I wrote: https://www.ultimatepp.org/forums/index.php?t=msg&th=101 32&start=0&
AFAIK, Tor client (not the browser, but the background process) can be configured to be used as a SOCKS proxy.
And SSH package already supports proxied connections (through WhenProxy callback, in which you hand over the TcpSocket handle to NetProxy, and let it connect for you via a proxy server).
So if you can configure the Tor client to act as a socks 5 proxy, then, "in theory", you may be able use SSH package through it. (or any other app that is designed to support NetProxy).
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sat, 02 December 2017 10:45] Report message to a moderator
|
|
|
|
| Re: SSH package for U++ [message #49036 is a reply to message #49033] |
Sun, 03 December 2017 08:35   |
alkema_jm
Messages: 25 Registered: November 2015
|
Promising Member |
|
|
Hello Oblivion,
> Think of it this way: I am implementing what I think Ultimate++ lacks (and what I need in U++). After all, these packages are meant to be used in U++ applications.
You did a very good job to make the packages for Ultimate++. I like to re use as much as possible. I don't like to 'reinvent weels'.
> By the way, recently I set up a GIT address where I upload 3rd party packages I wrote for U++.
I use github a lot to retrieve source code. All ('living') projects are on github.
> There are only several packages in the repo now but it will grow in time, once I clean up and publish the library I personally use: https://github.com/ismail-yilmaz/upp-components
I like Fossil program/concept (https://www.fossil-scm.org/xfer/timeline). Last two weeks of this year i will try to merge it with Ultimate++.
> I have good news and (somewhat) bad news: TOR is on my todo list (with WEBDAV, OAuth2, etc...), but it isn't an easy-to-implement protocol.
Ok. I like good news
> However "in theory" (I didn't actually test it) it is possible to use it, without writing a whole TOR client.
https://tor.stackexchange.com/questions/3421/route-c-through -tor-using-socks :
Tor is a socks5 proxy.
here is the socks5 rfc Protocol is https://www.ietf.org/rfc/rfc1928.txt
here is a guide to how socks5 works with tor https://samsclass.info/122/proj/how-socks5-works.html read this, it is VERY useful
if using sockets (I assume c++ uses sockets) you will need to
1. connect to tor (127.0.0.1:9050 by default)
2. Send authentication (5,1,0) see rfc part 3
3. Receive the tor response (5,0) see rfc part 3
4. Send Client's Connection request (5,1,0,3 + host length + a binary representation of the host and port) see rfc part 4
5. receive the tor response (5,0,0,1,0,0,0,0,0,0) see rfc part 6 (there can be a bunch of errors here, so watch out)
6. Send a binary representation of a http request to tor (Tor will forward this to the destination)
7. Receive the http response (will send the header first then the web page)
> There is a package called NetProxy (it is a Https/Socks4/4a/5 proxy adapter for U++) which, again, I wrote: https://www.ultimatepp.org/forums/index.php?t=msg&th=101 32&start=0&
Ok, Looks very promising
So if you can configure the Tor client to act as a socks 5 proxy, then, "in theory", you may be able use SSH package through it. (or any other app that is designed to support NetProxy).
> I see in "Tor is a socks5 proxy" on https://tor.stackexchange.com/questions/3421/route-c-through -tor-using-socks
> AFAIK, Tor client (not the browser, but the background process) can be configured to be used as a SOCKS proxy.
In de Tor logging it see "Opening Socks listener on 127.0.0.0:9050"
> And SSH package already supports proxied connections (through WhenProxy callback, in which you hand over the TcpSocket handle to NetProxy, and let it connect for you via a proxy server).
Oblivion, Must I insert NetProxy source code in Filezilla.exe or Tor.exe? N.B. My Tor.exe is the program to connect to the Tor-network. And has a sock listerer port on localhost port 9050.
Greetings Jan Marco
Appendix FileZilla client:
[Updated on: Sun, 03 December 2017 14:00] Report message to a moderator
|
|
|
|
|
|
| Re: SSH package for U++ [message #49042 is a reply to message #49041] |
Mon, 04 December 2017 22:46   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello Jan Marco,
Below is a simple example demonstrating the most basic way to connect to an ssh server via TOR protocol, using SSH package. (Naturally, it requires NetProxy package):
#include <Core/Core.h>
#include <SSH/SSH.h>
#include <NetProxy/NetProxy.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
// This example requires a running TOR daemon.
// Change below strings to your preferred values.
const char* ssh_host = "dummysshhostname";
const char* ssh_user = "dummysshusername";
const char* ssh_pass = "dummysshpassword";
int ssh_port = 22;
StdLogSetup(LOG_FILE|LOG_COUT);
Ssh::Trace();
NetProxy::Trace();
SshSession session;
session.WhenProxy = [=, &session] {
return NetProxy(session.GetSocket(), "127.0.0.1", 9050)
.Timeout(30000)
.Socks5()
.Auth("none", "none")
.Connect(ssh_host, ssh_port);
};
if(session.Timeout(60000).Connect(ssh_host, ssh_port, ssh_user, ssh_pass)) {
LOG("Successfully connected to " << ssh_host << " (over TOR)");
}
else
LOG("Ssh connection via TOR failed. " << session.GetErrorDesc());
}
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
|
|
|
|
|
|
| Re: SSH package for U++ [message #49070 is a reply to message #48973] |
Wed, 13 December 2017 17:46   |
alkema_jm
Messages: 25 Registered: November 2015
|
Promising Member |
|
|
Hello Oblivion,
> So while I'm not going to port filezilla to U++ (it'll need a lot of work), I'll come up with a simpler remote file browser demo.
FileZilla engine parses filestem info depending on Operating System.
bool ParseAsUnix(CLine &line, CDirentry &entry, bool expect_date);
bool ParseAsDos(CLine &line, CDirentry &entry);
bool ParseAsEplf(CLine &line, CDirentry &entry);
bool ParseAsVms(CLine &line, CDirentry &entry);
bool ParseAsIbm(CLine &line, CDirentry &entry);
bool ParseOther(CLine &line, CDirentry &entry);
bool ParseAsWfFtp(CLine &line, CDirentry &entry);
bool ParseAsIBM_MVS(CLine &line, CDirentry &entry);
bool ParseAsIBM_MVS_PDS(CLine &line, CDirentry &entry);
bool ParseAsIBM_MVS_PDS2(CLine &line, CDirentry &entry);
bool ParseAsIBM_MVS_Migrated(CLine &line, CDirentry &entry);
bool ParseAsIBM_MVS_Tape(CLine &line, CDirentry &entry);
int ParseAsMlsd(CLine &line, CDirentry &entry);
bool ParseAsOS9(CLine &line, CDirentry &entry);
I made a Visio diagram how I see the connection between SSH en SSH-server. I want to use https://github.com/PowerShell/Win32-OpenSSH because it compilers/links in vs2015:

There are a lot of info en Queue programs. I am looking First at librdkafka, maybe there are better ones.
https://content.pivotal.io/rabbitmq/understanding-when-to-us e-rabbitmq-or-apache-kafka
librdkafka is a C library implementation of the Apache Kafka protocol, containing both Producer and Consumer support. It was designed with message delivery reliability and high performance in mind, current figures exceed 1 million msgs/second for the producer and 3 million msgs/second for the consumer.
librdkafka is licensed under the 2-clause BSD license. https://github.com/edenhill/librdkafka
Maybe you have some advise or feedback 
Greetings Jan Marco
[Updated on: Wed, 13 December 2017 17:47] Report message to a moderator
|
|
|
|
| Re: SSH package for U++ [message #49106 is a reply to message #49070] |
Tue, 19 December 2017 14:27   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello Jan Marco,
Sorry I couldn't reply to you earlier.
I may be able to help but I'd need to know what you really want to achive. A server, client, or client-server?
Quote:
There are a lot of info en Queue programs. I am looking First at librdkafka, maybe there are better ones.
I'd never heeard of this one before. Could you elaborate on why you need this?
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
|
|
|
|
| Re: SSH package for U++ [message #49108 is a reply to message #48973] |
Tue, 19 December 2017 14:44   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello,
SSH package (both core classes and examples) is updated. As usual, you can find the latest package in the first message of this topic, or via below git address:
SSH: https://github.com/ismail-yilmaz/upp-components/tree/master/ Core/SSH
Examples: https://github.com/ismail-yilmaz/upp-components/tree/master/ Examples
SSH package gained new features:
- SshSession: It is now possible to use encryption keys loaded into memory. (Load keys from mem.)
- SshSession: Host based authentication method is added.
- Ssh: TraceVerbose() method is added. This method allows full-level logging (redirection) of libsssh2 diagnostic messages.
- Documentation updated.
Examples are updated too. Two new reference example is added to the package:
- SshOverTor: Demonstrates a basic SSH connection over TOR (Requires NetProxy package and a TOR daemon)
- SshLoggingExample: Demostrates logging capabilities of SSH pakcage.
SshLoggingExample demonstrates the powerful logging mechanism of SSH package:
#include <Core/Core.h>
#include <SSH/SSH.h>
using namespace Upp;
// To activate verbose logging, set the LIBSSH2TRACE flag.
// (e.g. via TheIDE->main configuration settings)
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT | LOG_FILE);
// Ssh::Trace();
Ssh::TraceVerbose(
// LIBSSH2_TRACE_SOCKET |
LIBSSH2_TRACE_KEX |
LIBSSH2_TRACE_AUTH |
LIBSSH2_TRACE_CONN |
// LIBSSH2_TRACE_SCP |
// LIBSSH2_TRACE_SFTP |
// LIBSSH2_TRACE_PUBLICKEY |
LIBSSH2_TRACE_ERROR
);
SshSession session;
auto b = session.Timeout(30000).Connect("demo:password@test.rebex.net:22");
LOG((b ? "Successfully connected to SSH2 server." : session.GetErrorDesc() << '\n'));
}
Reviews, patches, bug fixes, criticism, and suggestions are always appreciated.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
|
|
|
|
|
|
|
|
|
|
|
|
| Re: SSH package for U++ [message #49302 is a reply to message #48973] |
Fri, 19 January 2018 14:18   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello everyone,
SSH package is updated. This is a major update.
2018-01-19: Alpha version 2.
SshChannel reworked. It is now more flexible, and more analogous to a tcp socket.
Scp class gained a new Put method (and its corresponding operator overload).
NEW: SShShell is added to the package. It allows GUI integration and has a
"console mode" that supports both POSIX consoles and Windows command prompt.
NEW: SshTunnel class is added to the package. It allows TCP/IP and port forwarding
over SSH protocol.
Various bug fixes, and improvements.
Finally the code for SSH shell (console/interactive command line interface) has landed. I managed to get it work on Windows command prompt too (ver >= XP).
Examples are updated too. SshShell, SshShellNB, and SshShellGUI examples are added to the package.
SShShellGUI demonstrates a very basic SSH terminal with a non-blocking GUI.
You can always find the updated package on the first message of this topic or you can grab the code from:
https://github.com/ismail-yilmaz/upp-components/tree/master/ Core/SSH
Short videos:
SSH Shell (Demonstrating console apps, such as nano, and top): https://vimeo.com/250031042
SSH Shell GUI (demonstrates a very basic SSH terminal with a non-blocking GUI): https://vimeo.com/250352882
I appreciate bug reports, reviews, criticism, patches etc.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
|
|
|
|
|
|
|
|
| Re: SSH package for U++ [message #49334 is a reply to message #48973] |
Sun, 28 January 2018 12:13   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello all,
X11 forwarding support (the final missing piece of SSH package) code has finally landed.
X11 support is added as an operation mode for SshShell.
I believe that we have achieved a really remarkable result here (though this is a work-in-progress), given that:
- All SSH components have a very simple, easy to use, and uniform interface that supports time-constrained blocking, non-blocking operation modes and multithreading,
- They all work on Windows (tested on 7 & 10) and POSIX-compliant operating systems, and compile on both GCC/MingGW, and MSC.
- Shell component can work simultaneously with multiple X11 forwarding (per-shell), which is AFAIK a very rare feature among the libssh2 wrappers out there.
- And all this can be achieved writing very little code! (e.g. SshX11Shell has 10 LOCs for the actual code of X11-enabled full console, and SshShellGUI has 156 LOCs which are mostly usual U++ GUI setup)
Examples directory contains SshX11Shell and re-written SshShellGUI example with X11 and multiple shell support.
Here is a screenshot:

As usual, you can find the code and examples in the first message of this topic,
or you can grab them from: https://github.com/ismail-yilmaz/upp-components/tree/master/ Core/SSH
I appreciate bug reports, reviews, criticism, patches etc.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sun, 28 January 2018 12:43] Report message to a moderator
|
|
|
|
| Re: SSH package for U++ [message #49683 is a reply to message #48973] |
Mon, 02 April 2018 23:27   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello,
The new FTP package contains a simple FTP GUI example called FtpGUI. And now, here is its SFTP counterpart.
It has the same functionality. More importantly, their code are almost identical.
You can compare them from the below links:
FtpGUI:
https://github.com/ismail-yilmaz/upp-components/tree/master/ Examples/FtpGUI
SFtpGUI:
https://github.com/ismail-yilmaz/upp-components/tree/master/ Examples/SFtpGUI
Screenshot:

I'm considering writing multithreaded and multiprotocol (Local, FTP/SFTP/HTTP) global file get and put functions (similar to a lightweight GIO/KIO) for U++, based on AsyncWork, and using a url scheme.
If you have any thougts about this, I'd like to hear it.
Best regards,
Oblivion
-
Attachment: SFtpGUI.png
(Size: 49.24KB, Downloaded 1388 times)
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Mon, 02 April 2018 23:38] Report message to a moderator
|
|
|
|
| Re: SSH package for U++ [message #49703 is a reply to message #48973] |
Sat, 07 April 2018 16:25   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello all,
SSH package and examples are updated.
There are some small improvements and a small change:
- Blocking and non-blocking behaviour is now very similar to TcpSocket's.
- IsBlocking(), IsWorking() methods are added.
- WhenDo replaced with WhenWait, and WaitStep() method is added
Upcoming version will break the interface slighlty, I'm afraid. This will be a final breakage, as I am also going to declare the package a beta stage library.
Almost all of the issues are resolved, and last bits are going to be resovelved -hopefully- with the next version.
SSH package is currently very stable though.
Yet, as with the Ftp, I will also move this version of the SSH into the Attic foder, and maintain it for some time.
I am going to make the following changes:
Remove progress gate parameters in the getters and putters, and replace them with a single WhenProgress gate.
- Add WhenContent: Consumer function for incoming data transfers.
Change the Async (multithreaded) getters and putters:
- They will have progress gates with three-parameteres (id, done, total), instead of two. This proved more useful.
- They will use a URL similar to the one I use in the new version of FTP package.
- Additional variants for async functions, which will use One<Stream> and picks input data (for outgoing transfers).
- Update libssh2, as it has seen some activitiy, and gained new ciphers.
GIT repo: https://github.com/ismail-yilmaz/upp-components/tree/master/ Core/SSH
Examples: https://github.com/ismail-yilmaz/upp-components/tree/master/ Examples
Best regards,
Oblivion.
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sun, 08 April 2018 11:21] Report message to a moderator
|
|
|
|
| Re: SSH package for U++ [message #49736 is a reply to message #48973] |
Sun, 15 April 2018 00:39   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello,
SSH package updated. It has finally reached beta version.
2018-04-15: Consumer function support added to SFtp and SshChannel classes.
GetWaitStep() method is added to Ssh class.
Multithreaded methods rewritten.
It is now possible to use consumer functions. A reference example demonstrating this behavious is added, accordingly.
Also, multithreaded functions are rewritten. They now use a three-parameter progress gate.
Consumer function example (SFtpConsumerGet):
#include <Core/Core.h>
#include <SSH/SSH.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
// Ssh::Trace();
const char *file = "/pub/example/readme.txt";
String data;
SshSession session;
if(session.Timeout(30000).Connect("demo:password@test.rebex.net:22")) {
auto sftp = session.CreateSFtp();
sftp.WhenContent = [&data](const void *buf, int len)
{
data.Cat(static_cast<const char*>(buf), len);
};
sftp.Get(file);
LOG((!sftp.IsError() ? data : sftp.GetErrorDesc()));
}
else
LOG(session.GetErrorDesc());
}
Below you can find the latest package and the GIT address where you can always get the latest version.
GIT repo: https://github.com/ismail-yilmaz/upp-components/tree/master/ Core/SSH
Examples: https://github.com/ismail-yilmaz/upp-components/tree/master/ Examples
Older Version: https://github.com/ismail-yilmaz/upp-components/tree/master/ Attic/SSH
Please feel free to comment on it. Bug reports, reviews, criticism, etc. are appreciated.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sun, 15 April 2018 00:42] Report message to a moderator
|
|
|
|
| Re: SSH package for U++ [message #49750 is a reply to message #48973] |
Sat, 21 April 2018 08:12   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello,
SSH package and its reference examples are updated.
Two new multithreaded transfer methods are added to the package:
static AsyncWork<void> SFtp::AsyncConsumerGet(SshSession& session, const String& path, Event<int64, const void*, int> consumer)
static AsyncWork<void> Scp::AsyncConsumerGet(SshSession& session, const String& path, Event<int64, const void*, int> consumer)
These asynchronous methods use a consumer function to download data.
Also, two new reference examples are added to the package:
- SFtpConsumerGetMT: Demonstrates the usage of a consumer function for SFtp download, using a worker thread.
- SshPolymorphismNB: Demonstrates the polymorphism capability of SSH channels in non-blocking mode.
You can always get the latest version from the below git adresses.
GIT repo: https://github.com/ismail-yilmaz/upp-components/tree/master/ Core/SSH
Examples: https://github.com/ismail-yilmaz/upp-components/tree/master/ Examples
Older Version: https://github.com/ismail-yilmaz/upp-components/tree/master/ Attic/SSH
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sat, 21 April 2018 08:23] Report message to a moderator
|
|
|
|
| Re: SSH package for U++ [message #49784 is a reply to message #48973] |
Fri, 04 May 2018 22:08   |
Oblivion
Messages: 1266 Registered: August 2007
|
Senior Contributor |
|
|
Hello
SSH package is updated.
SSH:
2018-05-04: Ssh::GetWaitEvents() fixed.
SshTunnel::Validate() fixed.
Reference examples added to the package:
SshTunnelExample: Demonstrates the basic SSH tunneling (as tunnel/server) in blocking mode.
Note that the SSH tunnel example requires upp/reference/SocketClient and upp/reference/SocketServer examples.
it acts as a SSH server between the socket client and server. Although the example demonstrates one of the basic tunneling capabilities of the SshTunnel class,
very complex SSH tunnels can be built using it.
Code:
#include <Core/Core.h>
#include <SSH/SSH.h>
using namespace Upp;
// This example requires upp/reference/SocketServer and upp/reference/SocketClient examples.
// SocketClient: Set the port number to 3215.
//
// |SocketClient (client)|<---> |SshTunnelExample (tunnel/server)| <---> |SocketClient (server)|
bool SocketSendRecv(String& packet)
{
TcpSocket s;
if(!s.Connect("127.0.0.1", 3214)) {
LOG("SocketSend(): " << s.GetErrorDesc());
return false;
}
if(!s.PutAll(packet + '\n'))
return false;
packet = s.GetLine();
return !packet.IsEmpty();
}
void StartTunnel(SshSession& session)
{
SshTunnel listener(session);
if(!listener.Listen(3215, 5)) {
LOG("StartTunnel(): " << listener.GetErrorDesc());
return;
}
LOG("SSH tunnel (server mode): Waiting for the requests to be tunneled...");
for(;;) {
SshTunnel tunnel(session);
if(!tunnel.Accept(listener)) {
LOG("StartTunnel(): " << tunnel.GetErrorDesc());
return;
}
auto data = tunnel.GetLine();
LOG("Tunneled Request: " << data);
if(!data.IsEmpty() && SocketSendRecv(data)) {
LOG("Tunneled Response: " << data);
tunnel.Put(data + '\n');
}
}
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_FILE | LOG_COUT);
// Ssh::Trace();
SshSession session;
if(session.Timeout(30000).Connect("username:password@localhost:22")) {
StartTunnel(session.Timeout(Null));
return;
}
LOG(session.GetErrorDesc());
}
Below is the GIT address where you can always get the latest version.
GIT repo: https://github.com/ismail-yilmaz/upp-components/tree/master/ Core/SSH
Examples: https://github.com/ismail-yilmaz/upp-components/tree/master/ Examples
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Fri, 04 May 2018 22:44] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: SSH package for U++ [message #50119 is a reply to message #50070] |
Tue, 31 July 2018 11:07   |
 |
mirek
Messages: 14291 Registered: November 2005
|
Ultimate Member |
|
|
Oblivion wrote on Wed, 11 July 2018 08:35Hello Mirek,
Quote:
SSH looks pretty reasonable. Can I move to Core/SSH?
Of course! 
Quote:Put(Stream& in, const String& path);
I would expect path to be the first argument here... Do you insist on this order?
That's because I use "[source], [destination]..." order. I'd prefer it stay that way but I don't insist on it. It can be changed.
Whether the "source, target" or "target, source" is more natural is certainly debatable, however please notice that since the dawn of computer languages the custom is to write target = source (also see strcpy etc... That said, where handle or path is involved, I would probably like to have it as first parameter always.
Besides, it does not seem to be consistent anyway:
bool Get(SFtpHandle* handle, Stream& out);
bool Put(SFtpHandle* handle, Stream& in);
Now I am only scrathich the surface, mostly being interested in SFTP for now. Anyway, seeing that interface, I would probably like to change following things:
SFtpHandle* -> SFtpHandle - if something is "HANDLE", it should not be a pointer to handle.
Instead of:
auto sftp = session.CreateSFtp();
I would like to have
SFtp sftp(session);
Besides, I know that there is some movement to use 'auto' everywhere, but I strongly disagree with that, ESPECIALLY in reference examples.
More important: I thing I would remove whole bunch of Gets and Puts, leave only handle variant in sftp and then add SFtpStream instead. With methods provided in SFtp, it should be easy to do, and it would mostly remove "source/destination controversy".
Interestingly, it looks like the most important Gets / Puts are missing there
int Get(SFtpHandle h, void *ptr, int size);
bool Put(SFtpHandle h, const void *ptr, int size);
Anyway, it is now moved to Core/SSH and single example is now in reference - that is another issue I have not solved for now, there is a lot of examples and they really make sense, so maybe I will put them gradually to SSH subfolder.
I am giving you write access to Core/SSH and reference.
Mirek
|
|
|
|
Goto Forum:
Current Time: Wed Jun 03 20:10:22 GMT+2 2026
Total time taken to generate the page: 0.01577 seconds
|