国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
Upload a single file to multiple machines tool
Home Backend Development PHP Tutorial Upload a single file to multiple machines tool_PHP tutorial

Upload a single file to multiple machines tool_PHP tutorial

Jul 12, 2016 am 08:55 AM
android

Upload a single file to multiple machines tool

Usage example:
./mooon_upload -h=192.168.10.11,192.168.10.12 -p=6000 -u=root -P= 'root123' -s=./abc -d=/tmp/
means to upload the local file ./abc to the /tmp/ directory

    #include "mooon/net/libssh2.h"

  1. #include "mooon/sys/stop_watch.h"

  2. #include "mooon/ utils/args_parser.h"

  3. #include "mooon/utils/print_color.h"

  4. #include "mooon/utils/string_utils.h"

  5. #include "mooon/utils/tokener.h"

  6. #include

  7. #include


  8. // Comma separated list of remote hosts

  9. STRING_ARG_DEFINE(h, "", "remote hosts");

  10. // Sshd port number of the remote host

  11. INTEGER_ARG_DEFINE(uint16_t, p, 22, 10, 65535, "remote hosts port");

  12. // Username

  13. STRING_ARG_DEFINE(u, "root", "remote host user");

  14. // Password

  15. STRING_ARG_DEFINE(P , "", "remote host password");


  16. // Uploaded file path

  17. STRING_ARG_DEFINE(s, " ", "the source file uploaded");

  18. // Directory path where the file is stored after uploading

  19. STRING_ARG_DEFINE(d, "", "the directory to store" ; timeout seconds to remote host");


  20. // Result information

  21. struct ResultInfo

  22. {

  23. bool success; // true indicates successful execution

  24. std::string ip; // IP address of the remote host

  25. uint32_t seconds; // The time it takes to run, accurate to seconds


  26. ResultInfo()

  27. : success(false), seconds(0)

  28. {

  29. }


  30. std::string str() const

  31. {

  32. std::string tag = success? "SUCCESS": "FAILURE";

  33. return mooon::utils: :CStringUtils::format_string("[%s %s]: %u seconds", ip.c_str(), tag.c_str(), seconds);

  34. }

  35. };


  36. inline std::ostream& operator <<(std::ostream& out, const struct ResultInfo& result)

  37. {

  38. std::string tag = result.success? "SUCCESS": "FAILURE";

  39. out << "["PRINT_COLOR_YELLOW << result.ip << PRINT_COLOR_NONE" " << tag << "] " << result.seconds << " seconds";

  40. return out;

  41. }


  42. int main(int argc, char* argv[])

  43. {

  44. // Parse command line parameters

  45. std::string errmsg;

  46. if (!mooon::utils: :parse_arguments(argc, argv, &errmsg))

  47. {

  48. fprintf(stderr, "parameter error: %sn", errmsg.c_str());

  49. exit(1);

  50. }


  51. uint16_t port = mooon::argument::p ->value();

  52. std::string source = mooon::argument::s->value();

  53. std::string directory = mooon::argument::d->value();

  54. std::string hosts = mooon::argument::h->value();

  55. std::string user = mooon::argument::u->value();

  56. std::string password = mooon::argument::P->value( );

  57. mooon::utils::CStringUtils::trim(source);

  58. mooon::utils::CStringUtils::trim(directory);

  59. mooon::utils::CStringUtils::trim(hosts);

  60. mooon::utils::CStringUtils::trim(user);

  61. mooon::utils::CStringUtils::trim(password);


  62. // Check parameters (-s)

  63. if (source.empty())

  64. {

  65. fprintf(stderr, "parameter[-s]'s value not setn");

  66. exit(1);

  67. }


  68. // Check parameters (-d)

  69. if (directory.empty())

  70. {

  71. fprintf(stderr, "parameter[-d]'s value not setn") ;

  72. exit(1);

  73. }


  74. // Check parameters (-h )

  75. if (hosts.empty())

  76. {

  77. // Try to get the value from the environment variable

  78. const char* hosts_ = getenv("HOSTS");

  79. if (NULL == hosts_)

  80. {

  81. fprintf(stderr, "parameter[-h]'s value not setn");

  82. exit(1);

  83. }


  84. hosts= hosts_;

  85. mooon::utils::CStringUtils::trim(hosts);

  86. if (hosts .empty())

  87. {

  88. fprintf(stderr, "parameter[-h]'s value not setn");

  89. exit(1);

  90. }

  91. }


  92. // Check parameters (- u)

  93. if (user.empty())

  94. {
  95. fprintf(stderr, "parameter[-u]'s value not setn");
  96. exit(1);
  97. }

  98. // 檢查參數(shù)(-P)
  99. if (password.empty())
  100. {
  101. fprintf(stderr, "parameter[-P]'s value not setn");
  102. exit(1);
  103. }

  104. std::vector hosts_ip;
  105. const std::string& remote_hosts_ip = hosts;
  106. int num_remote_hosts_ip = mooon::utils::CTokener::split(&hosts_ip, remote_hosts_ip, ",", true);
  107. if (0 == num_remote_hosts_ip)
  108. {
  109. fprintf(stderr, "parameter[-h] errorn");
  110. exit(1);
  111. }

  112. std::string remote_filepath = directory std::string("/") mooon::utils::CStringUtils::extract_filename(source);
  113. std::vector results(num_remote_hosts_ip);
  114. for (int i=0; i
  115. {
  116. bool color = true;
  117. const std::string& remote_host_ip = hosts_ip[i];
  118. results[i].ip = remote_host_ip;
  119. results[i].success = false;

  120. fprintf(stdout, "["PRINT_COLOR_YELLOW"%s"PRINT_COLOR_NONE"]n", remote_host_ip.c_str());
  121. fprintf(stdout, PRINT_COLOR_GREEN);

  122. mooon::sys::CStopWatch stop_watch;
  123. try
  124. {
  125. int file_size = 0;
  126. mooon::net::CLibssh2 libssh2(remote_host_ip, port, user, password, mooon::argument::t->value());
  127. libssh2.upload(source, remote_filepath, &file_size);

  128. fprintf(stdout, "["PRINT_COLOR_YELLOW"%s"PRINT_COLOR_NONE"] SUCCESS: %d bytesn", remote_host_ip.c_str(), file_size);
  129. results[i].success = true;
  130. }
  131. catch (mooon::sys::CSyscallException& ex)
  132. {
  133. if (color)
  134. fprintf(stdout, PRINT_COLOR_NONE); // color = true;

  135. fprintf(stderr, "["PRINT_COLOR_RED"%s"PRINT_COLOR_NONE"] failed: %sn", remote_host_ip.c_str(), ex.str().c_str());
  136. }
  137. catch (mooon::utils::CException& ex)
  138. {
  139. if (color)
  140. fprintf(stdout, PRINT_COLOR_NONE); // color = true;

  141. fprintf(stderr, "["PRINT_COLOR_RED"%s"PRINT_COLOR_NONE"] failed: %sn", remote_host_ip.c_str(), ex.str().c_str());
  142. }

  143. results[i].seconds = stop_watch.get_elapsed_microseconds() / 1000000;
  144. std::cout << std::endl;
  145. }

  146. // 輸出總結(jié)
  147. std::cout << std::endl;
  148. std::cout << "================================" << std::endl;
  149. int num_success = 0; // 成功的個(gè)數(shù)
  150. int num_failure = 0; // 失敗的個(gè)數(shù)
  151. for (std::vector::size_type i=0; i
  152. {
  153. const struct ResultInfo& result_info = results[i];
  154. std::cout << result_info << std::endl;

  155. if (result_info.success)
  156. num_success;
  157. else
  158. num_failure;
  159. }
  160. std::cout << "SUCCESS: " << num_success << ", FAILURE: " << num_failure << std::endl;

  161. return 0;
  162. }


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1117250.htmlTechArticle上傳單個(gè)文件到多臺(tái)機(jī)器工具 使用示例: ./mooon_upload -h=192.168.10.11,192.168.10.12 -p=6000 -u=root -P='root123' -s=./abc -d=/tmp/ 表示將本地的文件./abc上傳...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades Sep 12, 2024 pm 12:23 PM

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

Samsung Galaxy S25 Ultra leaks in first render images with rumoured design changes revealed Samsung Galaxy S25 Ultra leaks in first render images with rumoured design changes revealed Sep 11, 2024 am 06:37 AM

OnLeaks has now partnered with Android Headlines to provide a first look at the Galaxy S25 Ultra, a few days after a failed attempt to generate upwards of $4,000 from his X (formerly Twitter) followers. For context, the render images embedded below h

IFA 2024 | TCL\'s NXTPAPER 14 won\'t match the Galaxy Tab S10 Ultra in performance, but it nearly matches it in size IFA 2024 | TCL\'s NXTPAPER 14 won\'t match the Galaxy Tab S10 Ultra in performance, but it nearly matches it in size Sep 07, 2024 am 06:35 AM

Alongside announcing two new smartphones, TCL has also announced a new Android tablet called the NXTPAPER 14, and its massive screen size is one of its selling points. The NXTPAPER 14 features version 3.0 of TCL's signature brand of matte LCD panels

Vivo Y300 Pro packs 6,500 mAh battery in a slim 7.69 mm body Vivo Y300 Pro packs 6,500 mAh battery in a slim 7.69 mm body Sep 07, 2024 am 06:39 AM

The Vivo Y300 Pro just got fully revealed, and it's one of the slimmest mid-range Android phones with a large battery. To be exact, the smartphone is only 7.69 mm thick but features a 6,500 mAh battery. This is the same capacity as the recently launc

Samsung Galaxy S24 FE billed to launch for less than expected in four colours and two memory options Samsung Galaxy S24 FE billed to launch for less than expected in four colours and two memory options Sep 12, 2024 pm 09:21 PM

Samsung has not offered any hints yet about when it will update its Fan Edition (FE) smartphone series. As it stands, the Galaxy S23 FE remains the company's most recent edition, having been presented at the start of October 2023. However, plenty of

iQOO Z9 Turbo Plus: Reservations begin for the potentially beefed-up series flagship iQOO Z9 Turbo Plus: Reservations begin for the potentially beefed-up series flagship Sep 10, 2024 am 06:45 AM

OnePlus'sister brand iQOO has a 2023-4 product cycle that might be nearlyover; nevertheless, the brand has declared that it is not done with itsZ9series just yet. Its final, and possibly highest-end,Turbo+variant has just beenannouncedas predicted. T

New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades Sep 12, 2024 pm 12:22 PM

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

Xiaomi Redmi Note 14 Pro Plus arrives as first Qualcomm Snapdragon 7s Gen 3 smartphone with Light Hunter 800 camera Xiaomi Redmi Note 14 Pro Plus arrives as first Qualcomm Snapdragon 7s Gen 3 smartphone with Light Hunter 800 camera Sep 27, 2024 am 06:23 AM

The Redmi Note 14 Pro Plus is now official as a direct successor to last year'sRedmi Note 13 Pro Plus(curr. $375 on Amazon). As expected, the Redmi Note 14 Pro Plus heads up the Redmi Note 14 series alongside theRedmi Note 14and Redmi Note 14 Pro. Li

See all articles