example_ssh2.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // example_ssh2.cpp : 定义控制台应用程序的入口点。
  2. //
  3. #include "stdafx.h"
  4. #include "example_ssh2.h"
  5. #include "WinSsh2Proc.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #endif
  9. // 唯一的应用程序对象
  10. CWinApp theApp;
  11. using namespace std;
  12. void Split(std::string str1, std::string str2, std::vector<std::string> &vt)
  13. {
  14. if ( str1.size() == 0 || str2.size() == 0 )
  15. return;
  16. int npos = str1.find(str2);
  17. while( std::string::npos != npos )
  18. {
  19. vt.push_back(str1.substr(0, npos));
  20. str1 = str1.substr(npos + str2.size());
  21. npos = str1.find(str2);
  22. }
  23. if ( str1.size() )
  24. vt.push_back(str1);
  25. }
  26. int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
  27. {
  28. int nRetCode = 0;
  29. // 初始化 MFC 并在失败时显示错误
  30. if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
  31. {
  32. // TODO: 更改错误代码以符合您的需要
  33. _tprintf(_T("错误: MFC 初始化失败\n"));
  34. nRetCode = 1;
  35. }
  36. else
  37. {
  38. // TODO: 在此处为应用程序的行为编写代码。
  39. CWinSsh2Proc winssh2;
  40. if ( winssh2.InitSocket() )
  41. {
  42. if ( winssh2.ssh2_connect("10.126.69.29", "wangjianfeng", "wangjianfeng@2021"))
  43. {
  44. std::string data;
  45. winssh2.ssh2_execute_command("ls", data);
  46. std::vector<std::string> strList;
  47. Split(data, "\n", strList);
  48. winssh2.ssh2_execute_command("md5sum /scbc_data/exchange/BAK_RT2841_2851_dailybuild/DailyBuild_RT2851_1231/USB/V8-T851T01-debug123103.img", data, 100000);
  49. winssh2.ssh2_execute_command("sha1sum /scbc_data/exchange/BAK_RT2841_2851_dailybuild/DailyBuild_RT2851_1231/USB/V8-T851T01-debug123103.img", data, 10000);
  50. winssh2.ssh2_execute_command("sha256sum /scbc_data/exchange/BAK_RT2841_2851_dailybuild/DailyBuild_RT2851_1231/USB/V8-T851T01-debug123103.img", data, 10000);
  51. }
  52. winssh2.ssh2_sftp_download("rt2851/Buildimg/V8-T841T01-LF1V001/Images/USB/build.prop", "D:\\sat\\c.img");
  53. }
  54. }
  55. system("pause");
  56. return nRetCode;
  57. }