本文整理汇总了C#中Renci.SshNet.SshClient.CreateShellStream方法的典型用法代码示例。如果您正苦于以下问题:C# SshClient.CreateShellStream方法的具体用法?C# SshClient.CreateShellStream怎么用?C# SshClient.CreateShellStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Renci.SshNet.SshClient
的用法示例。
在下文中一共展示了SshClient.CreateShellStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: connect
private static void connect(string hostName, string userName, string password)
{
if (client != null && client.IsConnected)
return;
var connectionInfo = new KeyboardInteractiveConnectionInfo(hostName, userName);
connectionInfo.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e)
{
foreach (var prompt in e.Prompts)
prompt.Response = password;
};
client = new SshClient(connectionInfo);
client.Connect();
sshStream = client.CreateShellStream("", 80, 40, 80, 40, 1024);
shellCommand("python", null);
using (var sr = new System.IO.StreamReader("queryJoints.py"))
{
String line;
while ((line = sr.ReadLine()) != null)
pythonCommand(line);
}
}
示例2: Main
static void Main(string[] args)
{
Console.WriteLine("fd");
try
{
ssh = new SshClient("10.141.3.110", "root", "ismail");
ssh.Connect();
//status = true;
//timer_enable();
}
//catch (Exception ex)
// {
// Console.Write(ex.Message);
//}
catch { }
if (true)
try
{
stream = ssh.CreateShellStream("xterm", 80, 50, 1024, 1024, 1024);
Thread.Sleep(100);
stream.WriteLine("telnet localhost 6571");
Thread.Sleep(100);
}
catch (Exception)
{
Console.WriteLine("hata");
}
Console.ReadKey();
}
示例3: Connect
public void Connect(ConnectionSettings settings, int terminalCols, int terminalRows)
{
Settings = settings;
if (dataThread != null)
throw new InvalidOperationException("Already connecting to a server.");
dataThread = new Thread(() =>
{
#if USE_LIBSSHNET
var connection = new LibSshNetConnection(serverAddress, username, (authentications.First() as PasswordAuthentication).Password);
stream = connection.GetStream();
#else
try
{
var authentications = new List<AuthenticationMethod>();
if (!string.IsNullOrEmpty(settings.KeyFilePath))
{
var privateKeyFile = new PrivateKeyFile(settings.KeyFilePath, settings.KeyFilePassphrase);
authentications.Add(new PrivateKeyAuthenticationMethod(settings.Username, privateKeyFile));
}
authentications.Add(new PasswordAuthenticationMethod(settings.Username, settings.Password));
ConnectionInfo connectionInfo = new ConnectionInfo(settings.ServerAddress, settings.ServerPort, settings.Username, authentications.ToArray());
Client = new SshClient(connectionInfo);
Client.Connect();
Client.KeepAliveInterval = TimeSpan.FromSeconds(20);
Stream = Client.CreateShellStream("xterm-256color", (uint) terminalCols, (uint) terminalRows, 0, 0, 1000);
if (Connected != null)
Connected(this, EventArgs.Empty);
}
catch (Exception ex)
{
ConnectionFailedEventArgs args = null;
if (ex is Renci.SshNet.Common.SshPassPhraseNullOrEmptyException ||
ex is InvalidOperationException)
args = new ConnectionFailedEventArgs(ConnectionError.PassphraseIncorrect, ex.Message);
else if (ex is SocketException)
args = new ConnectionFailedEventArgs(ConnectionError.NetError, ex.Message);
else if (ex is Renci.SshNet.Common.SshAuthenticationException)
args = new ConnectionFailedEventArgs(ConnectionError.AuthenticationError, ex.Message);
else
throw;
if (Failed != null)
Failed(this, args);
}
#endif
});
dataThread.Name = "Data Thread";
dataThread.IsBackground = true;
dataThread.Start();
}
示例4: SSH
private static MyAsyncInfo info; // unique class containing information obtained from an asynchronous read
// constructor that initializes the client object and creates a connection to the remote terminal
public SSH(string IP, string user, string pass)
{
// initilizes client object containing server information
client = new SshClient(IP, user, pass);
// connects to the server
client.Connect();
// creates a stream to communicate with the remote terminal
stream = client.CreateShellStream(@"xterm", 80, 24, 800, 600, 2048);
}
示例5: flash_px4
public static void flash_px4(string firmware_file)
{
if (is_solo_alive)
{
using (SshClient client = new SshClient("10.1.1.10", 22, "root", "TjSDBkAu"))
{
client.KeepAliveInterval = TimeSpan.FromSeconds(5);
client.Connect();
if (!client.IsConnected)
throw new Exception("Failed to connect ssh");
var retcode = client.RunCommand("rm -rf /firmware/loaded");
using (ScpClient scpClient = new ScpClient(client.ConnectionInfo))
{
scpClient.Connect();
if (!scpClient.IsConnected)
throw new Exception("Failed to connect scp");
scpClient.Upload(new FileInfo(firmware_file), "/firmware/" + Path.GetFileName(firmware_file));
}
var st = client.CreateShellStream("bash", 80, 24, 800, 600, 1024*8);
// wait for bash prompt
while (!st.DataAvailable)
System.Threading.Thread.Sleep(200);
st.WriteLine("loadPixhawk.py; exit;");
st.Flush();
StringBuilder output = new StringBuilder();
while (client.IsConnected)
{
var line = st.Read();
Console.Write(line);
output.Append(line);
System.Threading.Thread.Sleep(100);
if (output.ToString().Contains("logout"))
break;
}
}
}
else
{
throw new Exception("Solo is not responding to pings");
}
}
示例6: _main
static void _main()
{
BlackCore.basic.cParams args = bcore.app.args;
client = new System.Net.Sockets.TcpClient();
int wavInDevices = WaveIn.DeviceCount;
int selWav = 0;
for (int wavDevice = 0; wavDevice < wavInDevices; wavDevice++)
{
WaveInCapabilities deviceInfo = WaveIn.GetCapabilities(wavDevice);
Console.WriteLine("Device {0}: {1}, {2} channels", wavDevice, deviceInfo.ProductName, deviceInfo.Channels);
}
Console.Write("Select device: ");
selWav = int.Parse(Console.ReadLine());
Console.WriteLine("Selected device is " + selWav.ToString());
sshClient = new SshClient(args["host"], args["user"], args["pass"]);
sshClient.Connect();
if (sshClient.IsConnected)
{
shell = sshClient.CreateShellStream("xterm", 50, 50, 640, 480, 17640);
Console.WriteLine("Open listening socket...");
shell.WriteLine("nc -l " + args["port"] + "|pacat --playback");
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Try to connect...");
client.Connect(args["host"], int.Parse(args["port"]));
if (!client.Connected) return;
upStream = client.GetStream();
//====================
WaveInEvent wavInStream = new WaveInEvent();
wavInStream.DataAvailable += new EventHandler<WaveInEventArgs>(wavInStream_DataAvailable);
wavInStream.DeviceNumber = selWav;
wavInStream.WaveFormat = new WaveFormat(44100, 16, 2);
wavInStream.StartRecording();
Console.WriteLine("Working.....");
Console.ReadKey();
sshClient.Disconnect();
client.Close();
wavInStream.StopRecording();
wavInStream.Dispose();
wavInStream = null;
}
}
示例7: PythonConnection
public PythonConnection(string hostName, string userName, string password)
{
var connectionInfo = new KeyboardInteractiveConnectionInfo(hostName, userName);
connectionInfo.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e)
{
foreach (var prompt in e.Prompts)
prompt.Response = password;
};
client = new SshClient(connectionInfo);
client.Connect();
sshStream = client.CreateShellStream("", 80, 40, 80, 40, 1024);
shellCommand("python", null);
}
示例8: BasicRemoteOperations
internal BasicRemoteOperations(IDeploymentContext context, IHost host)
{
Context = context;
Sftp = new SftpClient(host.Hostname, host.Username, host.Password)
{
OperationTimeout = TimeSpan.FromMinutes(2),
ConnectionInfo = {Timeout = TimeSpan.FromMinutes(2)},
BufferSize = 1024*16
};
Sftp.Connect();
Shell = new SshClient(host.Hostname, host.Username, host.Password);
Shell.Connect();
ShellStream = Shell.CreateShellStream(
String.Format("{0}@{1}", host.Username, host.Hostname), 0, 0, 0, 0, 1024);
}
示例9: MySshStream
public MySshStream(string host, string username, string password)
{
SshClient ssh = new SshClient(GenerateConnectionInfo(host, username, password));
ssh.Connect();
if (!ssh.IsConnected)
throw new Exception("Can't connect to host: " + ssh.ConnectionInfo.Host);
var x = new Dictionary<Renci.SshNet.Common.TerminalModes, uint>();
//x.Add(Renci.SshNet.Common.TerminalModes.VERASE, 0);
stream = ssh.CreateShellStream("dumb", 80, 24, 800, 600, 1024,x);
stream.DataReceived += stream_DataReceived;
reader = new StreamReader(stream);
writer = new StreamWriter(stream);
writer.AutoFlush = true;
outputWriter = new StreamWriter(memoryStream);
shellOutpu = new StreamReader(memoryStream);
}
示例10: ReadBack
public void ReadBack()
{
var info = util.GetUsernameAndPassword();
var sclist = new CredentialSet(info.Item1);
var passwordInfo = sclist.Load().Where(c => c.Username == info.Item2).FirstOrDefault();
if (passwordInfo == null)
{
throw new ArgumentException(string.Format("Please create a generic windows credential with '{0}' as the target address, '{1}' as the username, and the password for remote SSH access to that machine.", info.Item1, info.Item2));
}
// Create the connection, but do it lazy so we don't do anything if we aren't used.
var host = info.Item1;
var username = info.Item2;
var password = passwordInfo.Password;
// Do the work.
var con = new SshClient(host, username, password);
con.Connect();
var s = con.CreateShellStream("Commands", 240, 200, 132, 80, 1024);
var reader = new StreamReader(s);
var writer = new StreamWriter(s);
writer.AutoFlush = true;
// Do the read command
writer.WriteLine("read -p \"hi there: \" bogus");
Thread.Sleep(200);
writer.Write("Life Is Great\n");
Thread.Sleep(200);
writer.WriteLine("set | grep bogus");
Thread.Sleep(200);
string l = "";
while ((l = reader.ReadLine()) != null)
{
Console.WriteLine(l);
}
Assert.Inconclusive();
}
示例11: Connect
public bool Connect()
{
System.Diagnostics.Debug.WriteLineIf(DEBUG, "ssh: connecting ....");
try
{
ConnectionInfo info = new PasswordConnectionInfo(_host,_port, _user, _pw);
_client = new SshClient(info);
_client.ErrorOccurred += SSHError;
_client.Connect();
_stream = _client.CreateShellStream("xterm", 80, 24, 800, 600, 1024);
System.Diagnostics.Debug.WriteLineIf(DEBUG, "ssh: connected");
return true;
}
catch (System.Exception e)
{
System.Diagnostics.Debug.WriteLineIf(DEBUG, "ssh: error while connecting:");
System.Diagnostics.Debug.WriteLine(e.Message);
System.Diagnostics.Debug.WriteLine(e.InnerException);
return false;
}
}
示例12: SSHForm_Load
private void SSHForm_Load(object sender, EventArgs e)
{
client = new SshClient(server, port, user,pwd);
client.Connect();
string reply = string.Empty;
shellStream = client.CreateShellStream("dumb", 80, 24, 800, 600, 1024);
reply = shellStream.Expect(new Regex(@":.*>#"), new TimeSpan(0, 0, 3));
shellStream.DataReceived += ShellStream_DataReceived;
richTextBox1.Text = "server connected\n";
richTextBox1.SelectionStart = richTextBox1.Text.Length;
richTextBox1.ScrollToCaret();
}
示例13: baglan
//
//
//
//
//int connect;
//connect degiskeninini simdilik kullanmiyoruz..
//baglanma fonksiyonu tanimlamasi
public void baglan()
{
ssh = new SshClient("10.141.3.110", "root", "ismail");
try
{
ssh = new SshClient("10.141.3.110", "root", "ismail");
ssh.Connect();
status = true;
//connect = 1;
}
catch
{
status = false;
tl.LogMessage("hata", "baglanti hatasi, tekrar deneyin.. [uc kapak getirene bardak hediye..]");
//connect = 0;
}
if(status==true)
{
try
{
stream = ssh.CreateShellStream("xterm", 80, 50, 1024, 1024, 1024);
Thread.Sleep(100);
stream.WriteLine("telnet localhost 6571");
Thread.Sleep(100);
kontrol();
}
catch
{
}
}
}
示例14: ExecuteEnableModeCommands
//выполнение команд в привилегированном режиме
private void ExecuteEnableModeCommands(SshClient sshClient, List<string> commands)
{
using (ShellStream client = sshClient.CreateShellStream("terminal", 80, 24, 800, 600, 1024))
{
SendCommandLF("enable", client);//переходим в привилегированный режим
SendCommand(_host.enablePassword, client);//подтверждаем наши права
foreach (string command in commands)
{
_listResult.Add(SendCommand(command, client));
}
//Console.WriteLine("4 [" + SendCommand("terminal pager 0", client) + "]");
//Console.WriteLine("3 [" + SendCommand("show version", client) + "]");
//Console.WriteLine("5 [" + SendCommand("show run", client) + "]");
//Console.WriteLine("1 [" + SendCommandW("show interface ?", client) + "]");
}
}
示例15: SSHConnection
public SSHConnection(string host, string username)
{
this._host = host;
this._username = username;
_ssh = new SshClient(_host, _username, Passwords.FetchPassword(_host, _username));
_ssh.Connect();
_stream = _ssh.CreateShellStream("commands", 240, 200, 132, 80, 240 * 200);
// Next job, wait until we get a command prompt
_stream.WriteLine("# this is a test");
DumpTillFind(_stream, "# this is a test");
_prompt = _stream.ReadLine();
}