Home » Developing U++ » UppHub » NetProxy package. (HTTP/SOCKS4/4a/5 with BIND support) encapsulation for U++
Re: NetProxy package. (HTTP/SOCKS4/4a/5 with BIND support) encapsulation for U++ [message #54208 is a reply to message #48812] |
Wed, 10 June 2020 13:11   |
Oblivion
Messages: 1223 Registered: August 2007
|
Senior Contributor |
|
|
Hi
I've added a Socks5-proxied SSH connection example to upp-components repo.
Example uses the Upp's Core/SSH package and also demonstrates the usage of WhenProxy event of SshSession class.
Here is the code:
#include <Core/Core.h>
#include <Core/SSH/SSH.h>
#include <NetProxy/NetProxy.h>
using namespace Upp;
// This example demonstrates a basic SSH2 connection over a Socks5 proxy.
// WARNING: The sole purpose of this example is to demonstrate the usage of
// NetProxy package with the SSH package. The example uses an anon.
// proxy server (with no authentication) to access a public SFTP
// server.
//
// NEVER USE A PUBLIC PROXY SERVER FOR YOUR SSH CONNECTIONS. IN FACT,
// IT IS HIGHLY RECOMMENDED TO COMPLETELY AVOID USING PROXY SERVERS FOR
// SENSITIVE/ENCRYPTED DATA TRANSFERS.
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
Ssh::Trace();
NetProxy::Trace();
const char *proxy_server = "88.249.26.113"; // Anonymous socks proxy server of a well-known ISP in Turkey (Turk Telekom).
const int proxy_port = 1080;
const char *ssh_server = "test.rebex.net"; // A well-known and popular SSH test server.
const int ssh_port = 22;
SshSession session;
session.WhenProxy = [&]() -> bool
{
NetProxy socksproxy(session.GetSocket(), proxy_server, proxy_port);
return socksproxy.Timeout(10000).Socks5().Connect(ssh_server, ssh_port);
};
if(session.Timeout(30000).Connect(ssh_server, ssh_port, "demo", "password")) {
SFtp sftp(session);
String s = sftp.LoadFile("./readme.txt");
if(!sftp.IsError()) {
RLOG("---------------------------");
RLOG(s);
RLOG("----------------------------");
}
return;
}
RLOG(session.GetErrorDesc());
}
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Wed, 10 June 2020 13:23] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Thu Aug 14 16:26:39 CEST 2025
Total time taken to generate the page: 0.11417 seconds
|