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); } }
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(); }
private void WaitForPrompt(ShellStream stream, bool timeOut) { if (_verbose) { if (timeOut) { stream.Expect(TimeSpan.FromSeconds(5), new Renci.SshNet.ExpectAction("#", (output) => { if (_console != null) _console.Log.Write(output); })); } else { stream.Expect(new Renci.SshNet.ExpectAction("#", (output) => { if (_console != null) _console.Log.Write(output); })); } } else { if (timeOut) stream.Expect("#", TimeSpan.FromSeconds(5)); else stream.Expect("#"); } }
/// <summary> /// Dump the input until we see a particular string in the returning text. /// </summary> /// <param name="s"></param> /// <param name="refreshTimeout">If we see something back from the host, reset the timeout counter</param> /// <param name="p"></param> /// <param name="failNow">Function that returns true if we should throw out right away</param> private void DumpTillFind(ShellStream s, string matchText, Action<string> ongo = null, bool dontdumplineofmatch = true, int secondsTimeout = 60*60, bool refreshTimeout = false, Func<bool> failNow = null ) { var lb = new LineBuffer(ongo); if (dontdumplineofmatch) { lb.Suppress(matchText); } var timeout = DateTime.Now + TimeSpan.FromSeconds(secondsTimeout); bool gotmatch = false; while (timeout > DateTime.Now) { s.Expect(TimeSpan.FromMilliseconds(100), new ExpectAction(matchText, l => { lb.Add(l); gotmatch = true; })); gotmatch = gotmatch || lb.Match(matchText); if (gotmatch) break; var data = s.Read(); if (data != null && data.Length > 0 && refreshTimeout) { timeout = DateTime.Now + TimeSpan.FromSeconds(secondsTimeout); } lb.Add(data); if (failNow != null && failNow()) { throw new SSHCommandInterruptedException("Calling routine requested termination of command"); } } if (!gotmatch) { throw new TimeoutException(string.Format("Waiting for '{0}' back from host and it was not seen inside of {1} seconds.", matchText, secondsTimeout)); } lb.DumpRest(); }
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(); }
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(); }
/// <summary> /// Read the output until we see a particular line. /// </summary> /// <param name="_stream"></param> /// <param name="p"></param> private void DumpTillFind(ShellStream stream, string matchText, Action<string> ongo = null) { while (true) { var l = stream.ReadLine(); if (l == null) { Thread.Sleep(100); } else { if (l.Contains(matchText)) { return; } else { if (ongo != null) { ongo(l); } } } } }
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(); }
public void ExeSSH(Object s) { using (var conninfo = new PasswordConnectionInfo(ip, log, pass)) { // try Renci.SshNet.SshClient client = new Renci.SshNet.SshClient(conninfo); // conninfo.Timeout = TimeSpan.FromSeconds(50); try { client.Connect(); } catch (Exception ex) { } try { Renci.SshNet.ShellStream stream = client.CreateShellStream("ssh", 180, 324, 1800, 3600, 8000); foreach (string command in list) { stream.Write(command + "\n"); System.Threading.Thread.Sleep(5000); string temp_string = stream.Read(); // File.WriteAllText(path, temp_string, Encoding.UTF8); File.WriteAllText("C:/" + ip + ".txt", temp_string, Encoding.UTF8); System.Threading.Thread.Sleep(5000); } client.Disconnect(); } catch (Exception ex) { } } }
public void Connect() { sshClient.Connect(); ss = sshClient.CreateShellStream(Host, 10, 10, 10, 10, 1024); thr = new Thread(thrRead); thr.Start(); }
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); }
public void Connect(ShellStream stream, ConnectionSettings settings) { notifier?.Stop(); notifier = new ShellStreamNotifier(terminalControl, stream); //notifier = new LoadingShellStreamNotifier(terminalControl, File.OpenRead("input.log")); //notifier = new SavingShellStreamNotifier(terminalControl, stream, File.OpenWrite("input.log")); viewModel.Connect(notifier, stream, settings); notifier.Start(); terminalControl.Terminal = viewModel.Terminal; }
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; } }
public bool TryConnect() { try { _sshConnection.Connect(); _connected = true; m_sshStream = _sshConnection.CreateShellStream("dumb", 80, 24, 800, 600, 1024); } catch (Exception e) { throw (e); } return true; }
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); }
public void Connect() { _scpClient.Connect(); _scpClient.KeepAliveInterval = TimeSpan.FromSeconds(10.0); _sshClient.Connect(); _sshClient.KeepAliveInterval = TimeSpan.FromSeconds(10.0); _shellStream = _sshClient.CreateShellStream("CONTROLLER-SHELL", 80, 24, 800, 600, 1024); _shellWriterStream = new StreamWriter(_shellStream) {AutoFlush = true}; _timer.Start(); _timer.Elapsed += KeepAlive; _sshClient.RunCommand( "mkdir -p /home/root/trik-sharp /home/root/trik-sharp/uploads /home/root/trik/scripts/trik-sharp"); Task.Run(() => _scpClient.Upload(new FileInfo(_libconwrapPath), "/home/root/trik-sharp/uploads/" + Path.GetFileName(_libconwrapPath))); }
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); }
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; } }
public void ExSSH(string ip, string log, string pass, List <String> list) { // foreach (string ipadd in ip) // { using (var conninfo = new PasswordConnectionInfo(ip, log, pass)) { Renci.SshNet.SshClient client = new Renci.SshNet.SshClient(conninfo); client.Connect(); Renci.SshNet.ShellStream stream = client.CreateShellStream("ssh", 180, 324, 1800, 3600, 8000); foreach (string command in list) { // var command = "show config modified"; stream.Write(command + "\n"); System.Threading.Thread.Sleep(10000); string temp_string = stream.Read(); // Console.Write(temp_string); File.WriteAllText("C:/" + ip + " thread n- " + System.Threading.Thread.CurrentThread.ManagedThreadId + ".txt", temp_string, Encoding.UTF8); // System.Threading.Thread.Sleep(5000); } client.Disconnect(); // } } }
public bool Reconnect(out ShellStream stream) { System.Diagnostics.Debug.WriteLineIf(DEBUG, "ssh: reconnecting ...."); Disconnect(); System.Threading.Thread.Sleep(500); if (Connect()) { stream = _stream; return true; } else { stream = null; return false; } }
public MyAsyncInfo(Byte[] array, ShellStream stream) { ByteArray = array; Stream = stream; }
public async Task<bool> ReconnectAsync() { return await Task.Run(() => { _timer.Elapsed -= KeepAlive; try { _scpClient.Disconnect(); _scpClient.Connect(); _sshClient.Disconnect(); _sshClient.Connect(); } catch (SocketException) { return false; } _shellStream = _sshClient.CreateShellStream("CONTROLLER-SHELL", 80, 24, 800, 600, 1024); _shellWriterStream = new StreamWriter(_shellStream) {AutoFlush = true}; _timer.Elapsed += KeepAlive; return true; }); }
public bool StartShellStream() { if (!ConnectSSH ()) return false; ManualResetEvent started = new ManualResetEvent(false); ShellStreamTask = new Task( () => { try { WriteLine("Starting terminal: Emulation = {0}",Host.TerminalEmulation); shellStream = sshClient.CreateShellStream(Host.TerminalEmulation,(uint)Host.TerminalCols,(uint)Host.TerminalRows,0,0,4096); shellStream.DataReceived += (object sender, ShellDataEventArgs e) => { Write(Encoding.UTF8.GetString(e.Data,0,e.Data.Length)); }; shellStream.ErrorOccurred+= (object sender, ExceptionEventArgs e) => { WriteLine(e.Exception.Message); keepShellAlive.Set(); }; if (!String.IsNullOrEmpty(Host.WorkingDir)) { Write("Changing dir: {0}...",Host.WorkingDir); shellStream.WriteLine(String.Format("cd {0}\r\n",Host.WorkingDir)); } started.Set(); keepShellAlive.Reset(); keepShellAlive.WaitOne(); WriteLine("\r\n*** Console Stream End"); } catch (Exception ex) { WriteLine("\r\n*** Console Stream Error: {0}",ex.Message); } finally { shellStream.Dispose(); shellStream = null; } }); ShellStreamTask.Start(); return started.WaitOne(5000); }
// // // // //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 { } } }
static string SendCommandW(string command, ShellStream shell) { StreamReader reader; StreamWriter writer; reader = new StreamReader(shell); writer = new StreamWriter(shell); writer.AutoFlush = true; writer.Write(command); while (shell.Length == 0) Thread.Sleep(500); return reader.ReadToEnd(); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { if (this.isDisposed) { return; } if (this.reader != null) { this.reader.Dispose(); this.reader = null; } if (this.writer != null) { this.writer.Dispose(); this.writer = null; } if (this.stream != null) { this.stream.Dispose(); this.stream = null; } if (this.client != null) { try { this.client.Disconnect(); } catch (Exception) { // this can happen because the IsConnected code was not ported to WinRT perfectly } this.client.Dispose(); this.client = null; } this.isDisposed = true; GC.SuppressFinalize(this); }
/// <summary> /// Establishes the connection to the server, using the specified <paramref name="terminal"/> for connection initialization (authentication, etc.). /// </summary> /// <param name="terminal">The terminal to use for connection initialization.</param> /// <returns>A value indicating whether the connection was successfully established.</returns> /// <exception cref="ObjectDisposedException">The connection object is already disposed.</exception> /// <exception cref="InvalidOperationException">The connection object is currently connected.</exception> public async Task<bool> ConnectAsync(IConnectionInitializingTerminal terminal) { this.CheckDisposed(); this.MustBeConnected(false); Lazy<string> username = new Lazy<string>(() => { if (string.IsNullOrEmpty(this.connectionData.Username)) { return terminal.ReadLineAsync("Username: "******"Username: "******"Password: "******"Password expired for user " + e.Username); do { var readNewPassword1Task = terminal.ReadLineAsync("New password: "******"Repeat new password: "******"Performing keyboard-interactive authentication."); } if (!string.IsNullOrEmpty(e.Instruction)) { terminal.WriteLine(e.Instruction); } foreach (var prompt in e.Prompts) { var readLineTask = terminal.ReadLineAsync(prompt.Request, echo: prompt.IsEchoed); readLineTask.Wait(); prompt.Response = readLineTask.Result; } }; connectionInfo = keyboardInteractiveConnectionInfo; break; case Model.AuthenticationType.PrivateKey: if (this.privateKeyData == null) { throw new Exception("Private Key '" + connectionData.PrivateKeyName + "' not found. Please correct the authentication details of the connection."); } PrivateKeyFile privateKey; try { using (var privateKeyStream = new MemoryStream(privateKeyData.Data)) { privateKey = new PrivateKeyFile(privateKeyStream); } } catch (SshPassPhraseNullOrEmptyException) { privateKey = null; } // In the normal PrivateKey authentication there is only a connection-local PrivateKeyAgent. var localPprivateKeyAgent = new Lazy<PrivateKeyAgent>(() => { terminal.WriteLine("Performing authentication with Private Key '" + connectionData.PrivateKeyName + "'."); if (privateKey == null) { string privateKeyPassword = terminal.ReadLineAsync("Private Key password: "******"Wrong Private Key password, please try again.", ex); } } } var pka = new PrivateKeyAgent(); pka.AddSsh2(privateKey.HostKey, connectionData.PrivateKeyName); return pka; }); var privateKeyConnectionInfo = new PrivateKeyConnectionInfo(this.connectionData.Host, this.connectionData.Port, username, localPprivateKeyAgent); connectionInfo = privateKeyConnectionInfo; break; case AuthenticationType.PrivateKeyAgent: if (PrivateKeyAgentManager.PrivateKeyAgent.ListSsh2().Count == 0) { throw new SshAuthenticationException("The private key agent doesn't contain any private keys."); } var globalPrivateKeyAgent = new Lazy<PrivateKeyAgent>(() => { var pka = PrivateKeyAgentManager.PrivateKeyAgent; terminal.WriteLine("Performing private key agent authentication."); return pka; }); var privateKeyAgentConnectionInfo = new PrivateKeyConnectionInfo(this.connectionData.Host, this.connectionData.Port, username, globalPrivateKeyAgent); connectionInfo = privateKeyAgentConnectionInfo; if (connectionData.PrivateKeyAgentForwarding == true) { forwardedPrivateKeyAgent = globalPrivateKeyAgent; terminal.WriteLine("Agent forwarding is enabled."); } break; default: throw new NotImplementedException("Authentication method '" + this.connectionData.Authentication + "' not implemented."); } connectionInfo.AuthenticationBanner += (sender, e) => { terminal.WriteLine(e.BannerMessage.Replace("\n", "\r\n")); }; this.client = new SshClient(connectionInfo); this.client.HostKeyReceived += (s, e) => { string fingerprint = string.Join(":", e.FingerPrint.Select(b => b.ToString("x2"))); bool trustHostKey = true; bool storeHostKey = false; string newHostKey = string.Join(null, e.HostKey.Select(b => b.ToString("x2"))); if (oldHostKey == null) { terminal.WriteLine("Remote Terminal has not yet cached a host key for this server."); terminal.WriteLine("Host key's fingerprint: " + fingerprint); terminal.WriteLine("Please make sure the fingerprint matches the server's actual host key."); trustHostKey = QueryYesNo(terminal, "Do you want to continue connecting to the host?"); if (trustHostKey) { storeHostKey = QueryYesNo(terminal, "Do you want to store this host key in the cache?"); } } else if (oldHostKey != newHostKey) { terminal.WriteLine("POSSIBLE SECURITY BREACH DETECTED!"); terminal.WriteLine("Remote Terminal has cached another host key for this server."); terminal.WriteLine("This could mean one of two things:"); terminal.WriteLine(" * the server's host key was changed by an administrator"); terminal.WriteLine(" * another computer is trying to intercept your connection"); terminal.WriteLine("Host key's new fingerprint: " + fingerprint); trustHostKey = QueryYesNo(terminal, "Do you want to continue connecting to the host?"); if (trustHostKey) { storeHostKey = QueryYesNo(terminal, "Do you want to update the cache with the new host key?"); } } e.CanTrust = trustHostKey; if (trustHostKey) { oldHostKey = newHostKey; } if (storeHostKey) { HostKeysDataSource.AddOrUpdate(this.connectionData.Host, this.connectionData.Port, newHostKey); } }; this.client.ConnectionInfo.Timeout = new TimeSpan(0, 15, 0); await Task.Run(() => { this.client.Connect(); }); this.client.ConnectionInfo.Timeout = new TimeSpan(0, 1, 0); var terminalModes = new Dictionary<TerminalModes, uint>(); terminalModes[TerminalModes.TTY_OP_ISPEED] = 0x00009600; terminalModes[TerminalModes.TTY_OP_OSPEED] = 0x00009600; this.stream = this.client.CreateShellStream(terminal.TerminalName, (uint)terminal.Columns, (uint)terminal.Rows, 0, 0, 1024, forwardedPrivateKeyAgent.Value, terminalModes.ToArray()); this.reader = new StreamReader(this.stream); this.writer = new StreamWriter(this.stream); this.writer.AutoFlush = true; return true; } catch (SshConnectionException ex) { terminal.WriteLine(ex.Message); retry = false; } catch (SshAuthenticationException ex) { terminal.WriteLine(ex.Message); if (connectionData.Authentication == AuthenticationType.PrivateKeyAgent) { terminal.WriteLine("Please load the necessary private key(s) into the private key agent."); retry = false; } else { retry = true; } } catch (Exception ex) { terminal.WriteLine(ex.Message); retry = false; } if (!retry || numRetries++ > 5) { return false; } } while (true); }
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(); }
//terminalden gelen cevabi okumak icin tanimlamlanan cevapoku fonksiyonu.. private void cevapoku(ShellStream stream) { try { while (stream.DataAvailable) { okunan = stream.ReadLine(); } okunan = Regex.Replace(okunan, @"\r", ""); int bas = okunan.IndexOf("<") + "<".Length; int uzunluk = okunan.IndexOf(">") - bas; pinler = okunan.Substring(bas, uzunluk); //pinoku = pinler.select(c => c.ToString()).ToArray(); } catch { tl.LogMessage("hata", "arduino okuma hatasi!!, kapat ac düzelir :) "); } }
static void Main(string[] args) { client = new SshClient("130.18.14.67", "", ""); client.Connect(); stream = client.CreateShellStream(@"xterm", 80, 24, 800, 600, 2048); string cmd = ""; //flush buffer stream.Flush(); while(true) { stream.DataReceived += StartAsyncRead; Console.WriteLine("Logged in success!: "); cmd = Console.ReadLine(); stream.WriteLine(cmd); } }