ZengCode.Com (The Thai Php Framework)  


Home   Download   Manual   About us    

Facebook   


MAIN MENU
เขียนโปรแกรมบน iPhone ด้วย MonoTouch
News
Php Tips
Ubuntu
Spring+Strut+Hibernate
Android Programming
Design Pattern By PHP
C# Design Pattern
Linux Quick Tips
C# Tips & Technique
C# using Linq น่าใช้จริงๆ
Java & JavaScript Tips
MAVEN
Database & SQL
ZengCode Framework Guide
Mac OSx
Zeng Code Code
Programming
IPhone (Tips and Trick)

Download เอกสารที่น่าสนใจ

     Free and Easy SSH in c#  (2009-09-09)

Free and Easy SSH in c#

If you’re looking for an easy way to communicate through ssh without paying rediculous prices for components, then read on.

Behold: SharpSSH (Download). It is a free communications component that is great for ssh.

Add the binary dll’s as a reference to your project.
The usage is surprisingly simple.

Tamir.SharpSsh.SshStream ssh = new Tamir.SharpSsh.SshStream(serverip, username, password);

The server ip does not need a port, it uses standard port 22.

string command = “killall -u username”; // could be any command
ssh.Write(command);
ssh.ReadResponse();

and when you are done…

ssh.Close();

To overcome issues with root password prompting you must set the server so that a username does not require a password.

 


Comment

michael kors outlet  (19 พฤษภาคม 2555)   
IP : 175.44.12.79

Have you brought michael kors outlet Michael kors watch michael kors outlet online before? How do michael kors outlet store you know michael kors bags outle that? Now I michael kors tote bags will talk michael kors handbags outlet something about michael kors factory outlet Michael Kors. Michael michael kors factory outlet online Kors is an michael kors diaper bags American Top michael kors outlet nj fashion designer. Kors Celine bags was born Celine outlet Karl Anderson Jr. in Celine bags outlet Long Island New Celine luggages York the Celine bags luggages son of Joan Celine tote bags Anderson Kors Celine Bags 2012 Krystosek a Celine outlet online former model.



Pee  (10 กันยายน 2552)   
IP : 210.4.138.41

อันนี้เวิร์คกว่าครับ ลองดูๆ

using System;
using System.Collections.Generic;
using System.Text;
using Tamir.SharpSsh;

namespace SSHCommand
{
    class Program
    {
        static void Main(string[] args)
        {

            SshShell ssh = new SshShell("192.168.142.128" "root");
             ssh.Password = "fujitsuthailand";
           

            Console.Write("Connecting...");
            ssh.Connect();
            Console.WriteLine("OK");


            Console.Write("Enter a pattern to expect in response [e.g. '#' '$' C:\\\\.*> etc...]: ");
            string pattern = Console.ReadLine();

            ssh.ExpectPattern = pattern;
            ssh.RemoveTerminalEmulationCharacters = true;

            Console.WriteLine();
            Console.WriteLine(ssh.Expect(pattern));

            while (ssh.ShellOpened)
            {
                Console.WriteLine();
                Console.Write("Enter some data to write ['Enter' to cancel]: ");
                string data = Console.ReadLine();
                if (data == "") break;
                ssh.WriteLine(data);

                string output = ssh.Expect(pattern);
                Console.WriteLine(output);
            }

            Console.Write("Disconnecting...");
            ssh.Close();
            Console.WriteLine("OK");
        }
    }
}

มาจากโค้ดข้างล่างนี้นะครับผม

 

SshConnectionInfo input = Util.GetInput();
SshShell ssh = new SshShell(input.Host input.User);
if(input.Pass != null) ssh.Password = input.Pass;
if(input.IdentityFile != null) ssh.AddIdentityFile( input.IdentityFile );

Console.Write("Connecting...");
ssh.Connect();
Console.WriteLine("OK");


Console.Write("Enter a pattern to expect in response [e.g. '#' '$' C:\\\\.*> etc...]: ");
string pattern = Console.ReadLine();

ssh.ExpectPattern = pattern;
ssh.RemoveTerminalEmulationCharacters = true;

Console.WriteLine();
Console.WriteLine( ssh.Expect( pattern ) );

while(ssh.ShellOpened)
{    
    Console.WriteLine();
    Console.Write("Enter some data to write ['Enter' to cancel]: ");
    string data = Console.ReadLine();
    if(data=="")break;
    ssh.WriteLine(data);

    string output = ssh.Expect( pattern );
    Console.WriteLine( output );
}

Console.Write("Disconnecting...");
ssh.Close();
Console.WriteLine("OK");


Name
Comment
Security CodeCAPTCHA Image

web hit counter

This page took 0.066413 seconds to load.