First, tools: Ssh.net
Website: Https://github.com/sshnet/SSH.NET
Second, call the command code:
Renci.SshNet.SshClient ssh =NewRenci.SshNet.SshClient ("192.168.1.104","Sindrol","123456"); Ssh. Connect (); while(true) {Console.WriteLine ("Please input command:"); varline =Console.ReadLine (); if(string. Isnullorwhitespace (line))Continue; varcmd =ssh. RunCommand (line); if(!string. Isnullorwhitespace (cmd. Error) Console.WriteLine (cmd). ERROR); ElseConsole.WriteLine (cmd. Result); } ssh. Disconnect ();
Third, upload the file code:
Renci.SshNet.SftpClient SFTP =NewRenci.SshNet.SftpClient ("192.168.1.104","Sindrol","123456"); Sftp.connect (); FileInfo fi=NewFileInfo (@"D:\Project\Matlab\rcnn.rar"); varAlllength =fi. Length; Sftp.uploadfile (NewSystem.IO.FileStream (FI. FullName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite),"/home/sindrol/aa.zip", (Pro) = {Console.WriteLine (pro *1.0d/alllength *1.0d). ToString ("P")); }); Console.WriteLine ("finished."); while(true) {System.Threading.Thread.Sleep ( -); }
Iv. usage:
1, generally used for a locally written bash corner, via sftp upload to the server, and then execute the Run command.
2, because it is a C # program implementation, so you can clear the implementation of multiple batch operations.
C # Remote Execute Linux system shell command and SFTP upload file