C++ mit SSH auf MySQL Datenbank

die_maus

Grünschnabel
Hallo,

ich möchte einen Datensatz von einer MySQL Datenbank aus dem Internet abholen via c++. Das Problem darin ist, dass fast alle Hoster den Zugriff von extern gesperrt haben. Eine Möglichkeit wäre es, wenn man über SSH ein tunnel aufbaut.

Nur kann ich das nicht. Ich weiss nicht wie man über C++ eine SSH Verbindung macht. Kann mir dabei jemand helfen?
 
Hallo,

du kannst glaube ich entweder über "ShellExecute" oder den "system()" Befehl normale Programme von deiner Console aus starten lassen. Damit müsstest du vom System einen SSH Tunnel mit Port-Weiterleitung einrichten lassen können und dann über Sockets Daten transferieren können.

Gruß,
Wolf
 
Hallo,

habe das gerade ein wenig gegoogelt, das mache ich dann mit plink.exe?

Habe mir plink runtergeladen und einen testaufbau gemacht. Wenn ich das in der Konsole ausführe

Code:
plink -v -ssh <sshuser>@localhost -pw <sshpassword> -L serverip:3306

Dann bekomme ich diese Fehlermeldung

Code:
Web-based version check ( --noweb to skip )
Recent cached web-check found... OK, v1.07 is current

Writing started: Wed Feb 20 09:34:07 2013

** Unused command line option: -v
** Unused command line option: -ssh
** Unused command line option: -xx
** Unused command line option: -pw
** Unused command line option: xx
** Unused command line option: -L
** Unused command line option: -xx:3306

Hallo,

habe das aus dem Link versucht.

http://www.example-code.com/vcpp/ssh.asp

Code:
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: void __thiscall CkSsh::Disconnect(void)" (?Disconnect@CkSsh@@QAEXXZ)" in Funktion ""void __cdecl ChilkatSample(void)" (?ChilkatSample@@YAXXZ)".
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: char const * __thiscall CkSsh::getReceivedText(int,char const *)" (?getReceivedText@CkSsh@@QAEPBDHPBD@Z)" in Funktion ""void __cdecl ChilkatSample(void)" (?ChilkatSample@@YAXXZ)".
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: bool __thiscall CkSsh::ChannelSendClose(int)" (?ChannelSendClose@CkSsh@@QAE_NH@Z)" in Funktion ""void __cdecl ChilkatSample(void)" (?ChilkatSample@@YAXXZ)".
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: bool __thiscall CkSsh::ChannelReceiveUntilMatch(int,char const *,char const *,bool)" (?ChannelReceiveUntilMatch@CkSsh@@QAE_NHPBD0_N@Z)" in Funktion ""void __cdecl ChilkatSample(void)" (?ChilkatSample@@YAXXZ)".
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: bool __thiscall CkSsh::SendReqExec(int,char const *)" (?SendReqExec@CkSsh@@QAE_NHPBD@Z)" in Funktion ""void __cdecl ChilkatSample(void)" (?ChilkatSample@@YAXXZ)".
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: int __thiscall CkSsh::OpenSessionChannel(void)" (?OpenSessionChannel@CkSsh@@QAEHXZ)" in Funktion ""void __cdecl ChilkatSample(void)" (?ChilkatSample@@YAXXZ)".
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: bool __thiscall CkSsh::AuthenticatePw(char const *,char const *)" (?AuthenticatePw@CkSsh@@QAE_NPBD0@Z)" in Funktion ""void __cdecl ChilkatSample(void)" (?ChilkatSample@@YAXXZ)".
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: void __thiscall CkSsh::put_IdleTimeoutMs(int)" (?put_IdleTimeoutMs@CkSsh@@QAEXH@Z)" in Funktion ""void __cdecl ChilkatSample(void)" (?ChilkatSample@@YAXXZ)".
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: bool __thiscall CkSsh::Connect(char const *,int)" (?Connect@CkSsh@@QAE_NPBDH@Z)" in Funktion ""void __cdecl ChilkatSample(void)" (?ChilkatSample@@YAXXZ)".
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: virtual __thiscall CkSsh::~CkSsh(void)" (****1CkSsh@@UAE@XZ)" in Funktion ""void __cdecl ChilkatSample(void)" (?ChilkatSample@@YAXXZ)".
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: char const * __thiscall CkMultiByteBase::lastErrorText(void)" (?lastErrorText@CkMultiByteBase@@QAEPBDXZ)" in Funktion ""void __cdecl ChilkatSample(void)" (?ChilkatSample@@YAXXZ)".
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: bool __thiscall CkSsh::UnlockComponent(char const *)" (?UnlockComponent@CkSsh@@QAE_NPBD@Z)" in Funktion ""void __cdecl ChilkatSample(void)" (?ChilkatSample@@YAXXZ)".
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: __thiscall CkSsh::CkSsh(void)" (****0CkSsh@@QAE@XZ)" in Funktion ""void __cdecl ChilkatSample(void)" (?ChilkatSample@@YAXXZ)".
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_main" in Funktion "___tmainCRTStartup".
1>D:\Visual Studio 2010\Projects\sql\Debug\sql.exe : fatal error LNK1120: 14 nicht aufgelöste externe Verweise.
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========

Ich glaube, das war der falsche Ansatz.
 
Habe das jetzt nochmal mit plink versucht, er bleibt bei Port 22 stehen.. Habe den mal im Router freigegeben, aber das interesiert den nicht.

Bekomme diese Ausgabe:

Code:
Looking up host "192.168.2.102"
Connecting to 192.168.2.102 port 22
Failed to connect to 192.168.2.102: Network Error: Connetion Refused
Network Error: Connetion Refused
FATAL ERROR: Network Error: Connetion Refused

Ich habe die selbe Eingabe gemacht bwie oben.

Ich bin für jede Möglichkeit offen, hast du für OpenSSH ein Beispielcode wie ich das aufbaue?
 
Habe das jetzt nochmal mit plink versucht, er bleibt bei Port 22 stehen.. Habe den mal im Router freigegeben, aber das interesiert den nicht.

Bekomme diese Ausgabe:

Code:
Looking up host "192.168.2.102"
Connecting to 192.168.2.102 port 22
Failed to connect to 192.168.2.102: Network Error: Connetion Refused
Network Error: Connetion Refused
FATAL ERROR: Network Error: Connetion Refused
Was ist denn 192.168.2.102 für ein Rechner? Dein Router?

Läuft denn darauf auch ein SSH Server? Sieht jedenfalls nicht so aus...
Ich habe die selbe Eingabe gemacht bwie oben.
Wo ist oben?
Ich bin für jede Möglichkeit offen, hast du für OpenSSH ein Beispielcode wie ich das aufbaue?
Nein, du müßtest die Quelldateien erstmal erstellen. Evtl. gibt es auch schon fertige Pakete, kann ich nicht sagen.

Alternativ könntest du auch NetSieben verwenden http://www.netsieben.com/products/ssh/ Da gibt es auch Beispielcode.
 
Zurück