Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwiftTclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcel

C++ Examples


ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
Firebase
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)

Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(C++) SSH Execute Remote Commands

Shows how to execute a command on an SSH server and retrieve the command output.

Note: This example requires Chilkat v9.5.0.65 or greater.

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Win Mobile 5.0/Pocket PC 2003

Solaris C/C++

FreeBSD C/C++

OpenBSD C/C++

MinGW C/C++

#include <CkSsh.h>

void ChilkatSample(void)
    {
    //  This example assumes Chilkat SSH/SFTP to have been previously unlocked.
    //  See Unlock SSH for sample code.

    CkSsh ssh;

    int port = 22;
    bool success = ssh.Connect("the-ssh-server.com",port);
    if (success != true) {
        std::cout << ssh.lastErrorText() << "\r\n";
        return;
    }

    //  Authenticate using login/password:
    success = ssh.AuthenticatePw("theSshLogin","theSshPassword");
    if (success != true) {
        std::cout << ssh.lastErrorText() << "\r\n";
        return;
    }

    //  Send some commands and get the output.
    const char *strOutput = ssh.quickCommand("df","ansi");
    if (ssh.get_LastMethodSuccess() != true) {
        std::cout << ssh.lastErrorText() << "\r\n";
        return;
    }

    std::cout << "---- df ----" << "\r\n";
    std::cout << strOutput << "\r\n";

    strOutput = ssh.quickCommand("echo hello world","ansi");
    if (ssh.get_LastMethodSuccess() != true) {
        std::cout << ssh.lastErrorText() << "\r\n";
        return;
    }

    std::cout << "---- echo hello world ----" << "\r\n";
    std::cout << strOutput << "\r\n";

    strOutput = ssh.quickCommand("date","ansi");
    if (ssh.get_LastMethodSuccess() != true) {
        std::cout << ssh.lastErrorText() << "\r\n";
        return;
    }

    std::cout << "---- date ----" << "\r\n";
    std::cout << strOutput << "\r\n";

    //  --------------
    //  Sample output:

    // 	---- df ----
    // 	Filesystem    512-blocks      Used  Available Capacity  iused     ifree %iused  Mounted on
    // 	/dev/disk2    2176716032 265736304 1910467728    13% 33281036 238808466   12%   /
    // 	devfs                382       382          0   100%      662         0  100%   /dev
    // 	map -hosts             0         0          0   100%        0         0  100%   /net
    // 	map auto_home          0         0          0   100%        0         0  100%   /home
    // 	/dev/disk3s2      374668    374668          0   100%    93665         0  100%   /Volumes/Google Chrome
    // 
    // 	---- echo hello world ----
    // 	hello world
    // 
    // 	---- date ----
    // 	Thu Dec 22 17:19:32 CST 2016
    }

 

© 2000-2016 Chilkat Software, Inc. All Rights Reserved.