Advertisement
Guest User

Untitled

a guest
Oct 10th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Tamir.SharpSsh;
  10. using System.Collections;
  11. using System.IO;
  12.  
  13. namespace mc_connect
  14. {
  15. public partial class Form1 : Form
  16. {
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. public class Util
  23. {
  24. /// <summary>
  25. /// Get input from the user
  26. /// </summary>
  27. ///
  28.  
  29. public static SshConnectionInfo GetInput()
  30. {
  31. string sFilename = @"server.txt";
  32. string sContent = "";
  33. StreamReader myFile = new StreamReader(sFilename, System.Text.Encoding.Default);
  34. sContent = myFile.ReadToEnd();
  35. myFile.Close();
  36.  
  37. string[] words = sContent.Split(':');
  38.  
  39.  
  40. SshConnectionInfo info = new SshConnectionInfo();
  41.  
  42. info.Host = words[1];
  43.  
  44. info.User = words[3];
  45.  
  46. info.Pass = words[5];
  47.  
  48.  
  49.  
  50.  
  51. return info;
  52. }
  53.  
  54. }
  55.  
  56. public struct SshConnectionInfo
  57. {
  58. public string Host;
  59. public string User;
  60. public string Pass;
  61. public string IdentityFile;
  62. }
  63.  
  64.  
  65.  
  66. private void button1_Click(object sender, EventArgs e)
  67. {
  68. string sFilename = @"server.txt";
  69. string sContent = "";
  70. StreamReader myFile = new StreamReader(sFilename, System.Text.Encoding.Default);
  71. sContent = myFile.ReadToEnd();
  72. myFile.Close();
  73. string[] words = sContent.Split(':');
  74.  
  75.  
  76. SshConnectionInfo input = Util.GetInput();
  77. SshExec exec = new SshExec(input.Host, input.User);
  78. if (input.Pass != null) exec.Password = input.Pass;
  79. if (input.IdentityFile != null) exec.AddIdentityFile(input.IdentityFile);
  80.  
  81.  
  82. exec.Connect();
  83.  
  84. //Command der ausgeführt wird
  85.  
  86. exec.RunCommand("cd Bukkit && screen -dmSL mcserver java -Xincgc -Xmx3000m -jar craftbukkit.jar ");
  87.  
  88.  
  89.  
  90. exec.Close();
  91. }
  92.  
  93. private void button2_Click(object sender, EventArgs e)
  94. {
  95. SshConnectionInfo input = Util.GetInput();
  96. SshExec exec = new SshExec(input.Host, input.User);
  97. if (input.Pass != null) exec.Password = input.Pass;
  98. if (input.IdentityFile != null) exec.AddIdentityFile(input.IdentityFile);
  99.  
  100.  
  101. exec.Connect();
  102.  
  103. //Command der ausgeführt wird
  104.  
  105. exec.RunCommand("screen -r mcserver -X quit");
  106.  
  107.  
  108.  
  109. exec.Close();
  110.  
  111. }
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement