C # Remote Execute Linux system shell command and SFTP upload file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.