1 #include "SshBasics.h" 2 3 //#define SSH_KBAUTH // Enables ssh keyboard authentication method. 4 5 #define SSH_SFTP 6 7 // Important note: The scp, X11 forwarding and tcp-ip/port forwarding (tunnel) examples will not 8 // work with the public ssh test server used in this reference example (test.rebex.net). In order 9 // to run these examples you can set up an easy-to-use ssh server (e.g. OpenSSH) on a local 10 // machine for testing purposes. 11 12 CONSOLE_APP_MAIN 13 { 14 StdLogSetup(LOG_COUT|LOG_FILE); 15 #ifdef flagLIBSSH2TRACE 16 VerboseLogging(); 17 #else 18 // Ssh::Trace(); 19 #endif 20 21 SshSession session; 22 #if defined(SSH_KBAUTH) 23 session.KeyboardAuth(); 24 session.WhenKeyboard = [](String title, String instructions, String prompt) __anon93e57ad70102() 25 { 26 // Title and insctructions are optional and might be empty. 27 if(!IsNull(title)) 28 LOG(title); 29 if(!IsNull(instructions)) 30 LOG(instructions); 31 32 Cout() << prompt; 33 return ReadSecret(); // "password" 34 }; 35 #endif 36 if(session.Timeout(30000).Connect("demo:password@test.rebex.net:22")) { 37 #if defined(SSH_SFTP) 38 SFtpGet(session); 39 #elif defined(SSH_SFTP_STREAM) 40 SFtpStreamGet(session); 41 #elif defined(SSH_SFTP_TRANSPARENCY) 42 SFtpTransparency(session); 43 #elif defined(SSH_SFTP_MT) 44 SFtpAsyncGet(session); 45 #elif defined(SSH_EXEC) 46 ExecListDir(session); 47 #elif defined(SSH_EXEC_MT) 48 ExecAsyncListDir(session); 49 #elif defined(SSH_SCP) 50 ScpGet(session); 51 #elif defined(SSH_SHELL) 52 ShellConsole(session); 53 #elif defined(SSH_SHELL_X11) 54 X11Forwarding(session); 55 #elif defined(SSH_TUNNEL) 56 ForwardTcpIp(session); 57 #elif defined(SSH_PICK_SEMANTICS) 58 SshPick(session); 59 #endif 60 return; 61 } 62 LOG(session.GetErrorDesc()); 63 } 64