Advertisement
Guest User

kak

a guest
Apr 27th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. namespace testCommunicationRpi
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. string IP = "192.168.137.100";
  8. string userName = "pi";
  9. string password = "raspberry";
  10.  
  11. //// Setup Credentials and Server Information
  12. //ConnectionInfo ConnNfo = new ConnectionInfo(IP, 22, userName,
  13. // new AuthenticationMethod[]{
  14.  
  15. // // Pasword based Authentication
  16. // new PasswordAuthenticationMethod(userName,password)
  17.  
  18. // //// Key Based Authentication (using keys in OpenSSH Format)
  19. // //new PrivateKeyAuthenticationMethod("username",new PrivateKeyFile[]{
  20. // // new PrivateKeyFile(@"..\openssh.key","passphrase")
  21. // //}),
  22. // }
  23. //);
  24.  
  25. //// Execute a (SHELL) Command - prepare upload directory
  26. //using (var sshclient = new SshClient(ConnNfo))
  27. //{
  28. // sshclient.Connect();
  29. // using (var cmd = sshclient.CreateCommand("mkdir -p /tmp/uploadtest && chmod +rw /tmp/uploadtest"))
  30. // {
  31. // cmd.Execute();
  32. // Console.WriteLine("Command>" + cmd.CommandText);
  33. // Console.WriteLine("Return Value = {0}", cmd.ExitStatus);
  34. // }
  35. // sshclient.Disconnect();
  36. //}
  37.  
  38.  
  39. //Execute(SHELL) Commands
  40. //using (var sshclient = new SshClient(ConnNfo))
  41. //{
  42. // sshclient.Connect();
  43.  
  44. // // quick way to use ist, but not best practice - SshCommand is not Disposed, ExitStatus not checked...
  45. // //Console.WriteLine(sshclient.CreateCommand("cd /tmp && ls -lah").Execute());
  46. // //Console.WriteLine(sshclient.CreateCommand("pwd").Execute());
  47. // //Console.WriteLine(sshclient.CreateCommand("cd /tmp/uploadtest && ls -lah").Execute());
  48.  
  49. // Console.WriteLine("Connected");
  50.  
  51. // Console.WriteLine(sshclient.CreateCommand("cd masterproef").Execute());
  52. // Console.WriteLine("cd");
  53.  
  54. // Console.WriteLine(sshclient.CreateCommand("python camera4.py").Execute());
  55. // Console.WriteLine("foto");
  56.  
  57.  
  58.  
  59. // sshclient.Disconnect();
  60. //}
  61.  
  62. ////2de test
  63. //using (var client = new SshClient(IP, userName, password))
  64. //{
  65. // client.Connect();
  66. // client.RunCommand("cd masterproef");
  67. // client.RunCommand("nano test.py");
  68. // //client.RunCommand("python camera4.py");
  69. // //Thread.Sleep(5000);
  70. // client.Disconnect();
  71. //}
  72.  
  73. ////3de test
  74. //SshClient cSSH = new SshClient(IP, 22, userName, password);
  75. //cSSH.Connect();
  76. //SshCommand x = cSSH.RunCommand("cd masterproef");
  77. //x = cSSH.RunCommand("nano test.py");
  78. //cSSH.Disconnect();
  79. //cSSH.Dispose();
  80.  
  81. //test4
  82. //ProcessStartInfo cmd = new ProcessStartInfo();
  83. //cmd.FileName = @"C:\Users\UGent\Documents\SCHOOL\Masterproef\VisualStudio\putty.exe";
  84. //cmd.UseShellExecute = false;
  85. //cmd.RedirectStandardInput = true;
  86. //cmd.RedirectStandardOutput = true;
  87. //cmd.Arguments = "-ssh pi@192.168.137.100 22 -pw raspberry";
  88.  
  89.  
  90. ////string output = cmd.StandardOutput.ReadToEnd();
  91.  
  92. //using (Process process = Process.Start(cmd))
  93. //{
  94. // Console.WriteLine("start");
  95. // process.StandardInput.WriteLine("cd masterproef");
  96. // process.StandardInput.WriteLine("nano test.py");
  97. // process.WaitForExit();
  98. //}
  99.  
  100. // test 5
  101. //ProcessStartInfo startinfo = new ProcessStartInfo();
  102. //startinfo.FileName = @"C:\Users\UGent\Documents\SCHOOL\Masterproef\VisualStudio\plink.exe";
  103. //startinfo.Arguments = "-ssh pi@192.168.137.100 22 -pw raspberry";
  104. //Process process = new Process();
  105. //process.StartInfo = startinfo;
  106. //process.StartInfo.UseShellExecute = false;
  107. //process.StartInfo.RedirectStandardInput = true;
  108. //process.Start();
  109. //process.StandardInput.WriteLine("cd masterproef");
  110. //process.WaitForExit();
  111. //Console.ReadKey();
  112.  
  113. //Console.ReadKey();
  114.  
  115. // test 6
  116. //ProcessStartInfo startinfo = new ProcessStartInfo();
  117. //startinfo.FileName = @"C:\Users\UGent\Documents\SCHOOL\Masterproef\VisualStudio\plink.exe";
  118. //startinfo.Arguments = "-ssh pi@192.168.137.100 22 -pw raspberry";
  119. //Process process = new Process();
  120. //process.StartInfo = startinfo;
  121. //process.StartInfo.UseShellExecute = false;
  122. //process.StartInfo.RedirectStandardInput = true;
  123. //process.Start();
  124. //process.StandardInput.WriteLine("cd masterproef");
  125. //process.WaitForExit();
  126. //Console.ReadKey();
  127.  
  128.  
  129. //test 7
  130.  
  131. //bool running = true;
  132. SshClient client = new SshClient(IP, userName, password);
  133. client.Connect();
  134.  
  135. //while (running)
  136. //{
  137. // string input = GetInput();
  138. // running = ProcessInput(input, client);
  139. //}
  140.  
  141. client.RunCommand("cd masterproef");
  142. client.RunCommand("python camera4.py");
  143.  
  144. client.Disconnect();
  145.  
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement