Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace testCommunicationRpi
- {
- class Program
- {
- static void Main(string[] args)
- {
- string IP = "192.168.137.100";
- string userName = "pi";
- string password = "raspberry";
- //// Setup Credentials and Server Information
- //ConnectionInfo ConnNfo = new ConnectionInfo(IP, 22, userName,
- // new AuthenticationMethod[]{
- // // Pasword based Authentication
- // new PasswordAuthenticationMethod(userName,password)
- // //// Key Based Authentication (using keys in OpenSSH Format)
- // //new PrivateKeyAuthenticationMethod("username",new PrivateKeyFile[]{
- // // new PrivateKeyFile(@"..\openssh.key","passphrase")
- // //}),
- // }
- //);
- //// Execute a (SHELL) Command - prepare upload directory
- //using (var sshclient = new SshClient(ConnNfo))
- //{
- // sshclient.Connect();
- // using (var cmd = sshclient.CreateCommand("mkdir -p /tmp/uploadtest && chmod +rw /tmp/uploadtest"))
- // {
- // cmd.Execute();
- // Console.WriteLine("Command>" + cmd.CommandText);
- // Console.WriteLine("Return Value = {0}", cmd.ExitStatus);
- // }
- // sshclient.Disconnect();
- //}
- //Execute(SHELL) Commands
- //using (var sshclient = new SshClient(ConnNfo))
- //{
- // sshclient.Connect();
- // // quick way to use ist, but not best practice - SshCommand is not Disposed, ExitStatus not checked...
- // //Console.WriteLine(sshclient.CreateCommand("cd /tmp && ls -lah").Execute());
- // //Console.WriteLine(sshclient.CreateCommand("pwd").Execute());
- // //Console.WriteLine(sshclient.CreateCommand("cd /tmp/uploadtest && ls -lah").Execute());
- // Console.WriteLine("Connected");
- // Console.WriteLine(sshclient.CreateCommand("cd masterproef").Execute());
- // Console.WriteLine("cd");
- // Console.WriteLine(sshclient.CreateCommand("python camera4.py").Execute());
- // Console.WriteLine("foto");
- // sshclient.Disconnect();
- //}
- ////2de test
- //using (var client = new SshClient(IP, userName, password))
- //{
- // client.Connect();
- // client.RunCommand("cd masterproef");
- // client.RunCommand("nano test.py");
- // //client.RunCommand("python camera4.py");
- // //Thread.Sleep(5000);
- // client.Disconnect();
- //}
- ////3de test
- //SshClient cSSH = new SshClient(IP, 22, userName, password);
- //cSSH.Connect();
- //SshCommand x = cSSH.RunCommand("cd masterproef");
- //x = cSSH.RunCommand("nano test.py");
- //cSSH.Disconnect();
- //cSSH.Dispose();
- //test4
- //ProcessStartInfo cmd = new ProcessStartInfo();
- //cmd.FileName = @"C:\Users\UGent\Documents\SCHOOL\Masterproef\VisualStudio\putty.exe";
- //cmd.UseShellExecute = false;
- //cmd.RedirectStandardInput = true;
- //cmd.RedirectStandardOutput = true;
- //cmd.Arguments = "-ssh pi@192.168.137.100 22 -pw raspberry";
- ////string output = cmd.StandardOutput.ReadToEnd();
- //using (Process process = Process.Start(cmd))
- //{
- // Console.WriteLine("start");
- // process.StandardInput.WriteLine("cd masterproef");
- // process.StandardInput.WriteLine("nano test.py");
- // process.WaitForExit();
- //}
- // test 5
- //ProcessStartInfo startinfo = new ProcessStartInfo();
- //startinfo.FileName = @"C:\Users\UGent\Documents\SCHOOL\Masterproef\VisualStudio\plink.exe";
- //startinfo.Arguments = "-ssh pi@192.168.137.100 22 -pw raspberry";
- //Process process = new Process();
- //process.StartInfo = startinfo;
- //process.StartInfo.UseShellExecute = false;
- //process.StartInfo.RedirectStandardInput = true;
- //process.Start();
- //process.StandardInput.WriteLine("cd masterproef");
- //process.WaitForExit();
- //Console.ReadKey();
- //Console.ReadKey();
- // test 6
- //ProcessStartInfo startinfo = new ProcessStartInfo();
- //startinfo.FileName = @"C:\Users\UGent\Documents\SCHOOL\Masterproef\VisualStudio\plink.exe";
- //startinfo.Arguments = "-ssh pi@192.168.137.100 22 -pw raspberry";
- //Process process = new Process();
- //process.StartInfo = startinfo;
- //process.StartInfo.UseShellExecute = false;
- //process.StartInfo.RedirectStandardInput = true;
- //process.Start();
- //process.StandardInput.WriteLine("cd masterproef");
- //process.WaitForExit();
- //Console.ReadKey();
- //test 7
- //bool running = true;
- SshClient client = new SshClient(IP, userName, password);
- client.Connect();
- //while (running)
- //{
- // string input = GetInput();
- // running = ProcessInput(input, client);
- //}
- client.RunCommand("cd masterproef");
- client.RunCommand("python camera4.py");
- client.Disconnect();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement