1 #include "ksshprocess.h"
6 int main(int argc
, char *argv
[]) {
9 cout
<< "Usage: " << argv
[0] <<
10 " <ssh path> <host> <username> <password>" << endl
;
14 KSshProcess
ssh(argv
[1]);
15 cout
<< ssh
.version() << endl
;
17 KSshProcess::SshOptList opts
;
18 KSshProcess::SshOpt opt
;
20 opt
.opt
= KSshProcess::SSH_PORT
;
24 opt
.opt
= KSshProcess::SSH_HOST
;
25 opt
.str
= QString(argv
[2]);
28 opt
.opt
= KSshProcess::SSH_USERNAME
;
29 opt
.str
= QString(argv
[3]);
32 // opt.opt = KSshProcess::SSH_PASSWD;
33 // opt.str = QString(argv[4]);
36 if( !ssh
.setOptions(opts
) ) {
37 cout
<< "ksshprocesstest: setOptions failed" << endl
;
47 while( !stop
&& !(connected
= ssh
.connect()) ) {
48 cout
<< "ksshprocesstest: Error num - " << ssh
.error() << endl
;
49 cout
<< "ksshprocesstest: Error msg - " << qPrintable(ssh
.errorMsg()) << endl
;
50 switch( ssh
.error() ) {
51 case KSshProcess::ERR_NEED_PASSWD
:
52 case KSshProcess::ERR_NEED_PASSPHRASE
:
55 cout
<< "password is " << buf
<< endl
;
56 ssh
.setPassword(QString(buf
));
58 case KSshProcess::ERR_NEW_HOST_KEY
:
59 case KSshProcess::ERR_DIFF_HOST_KEY
:
60 cout
<< "Accept host key? (y/n): ";
62 cout
<< "Answered " << c
<< endl
;
63 ssh
.acceptHostKey(c
== 'y' ? true : false);
65 case KSshProcess::ERR_AUTH_FAILED
:
66 cout
<< "ksshprocesstest: auth failed." << endl
;
69 case KSshProcess::ERR_AUTH_FAILED_NEW_KEY
:
70 cout
<< "ksshprocesstest: auth failed because of new key." << endl
;
73 case KSshProcess::ERR_AUTH_FAILED_DIFF_KEY
:
74 cout
<< "ksshprocesstest: auth failed because of changed key." << endl
;
78 case KSshProcess::ERR_INTERACT
:
79 case KSshProcess::ERR_INTERNAL
:
80 case KSshProcess::ERR_UNKNOWN
:
81 case KSshProcess::ERR_INVALID_STATE
:
82 case KSshProcess::ERR_CANNOT_LAUNCH
:
83 case KSshProcess::ERR_HOST_KEY_REJECTED
:
84 cout
<< "ksshprocesstest: FATAL ERROR" << endl
;
92 cout
<< "ksshprocesstest: Successfully connected to " << argv
[2] << endl
;
95 cout
<< "ksshprocesstest: Connect to " << argv
[2] << " failed." << endl
;