public void Write([ReadOnlyArray()] byte[] data, int offset, int length) { if (!_ready || _channel == null) { throw new Exception("channel not ready"); } _channel.Transmit(data, offset, length); }
internal override void Write(byte[] data, int offset, int length) { if (_socketStatus != SocketStatus.Ready) { throw new SSHException("channel not ready"); } _channel.Transmit(data, offset, length); }
public void Transmit(byte[] data, int offset, int length) { lock (_connection) { if (!_closed && !_sentEOF) { _channel.Transmit(data, offset, length); } } }
/// <summary> /// Writes data. /// </summary> /// <param name="buffer">Buffer</param> /// <param name="length">Length</param> public void Write(byte[] buffer, int length) { if (_status != StreamStatus.Opened) { throw new SCPClientInvalidStatusException(); } Debug.Assert(_channel != null); _channel.Transmit(buffer, 0, length); }
private static void AgentForward() { SSHConnectionParameter f = new SSHConnectionParameter(); f.EventTracer = new Tracer(); //to receive detailed events, set ISSHEventTracer Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); f.Protocol = SSHProtocol.SSH2; //this sample works on both SSH1 and SSH2 string host_ip = "172.22.1.15"; //<--!!! [TO USERS OF Granados] f.UserName = "******"; //<--!!! if you try this sample, edit these values for your environment! string password = ""; s.Connect(new IPEndPoint(IPAddress.Parse(host_ip), 22)); //22 is the default SSH port //former algorithm is given priority in the algorithm negotiation f.PreferableHostKeyAlgorithms = new PublicKeyAlgorithm[] { PublicKeyAlgorithm.RSA, PublicKeyAlgorithm.DSA }; f.PreferableCipherAlgorithms = new CipherAlgorithm[] { CipherAlgorithm.Blowfish, CipherAlgorithm.TripleDES }; f.WindowSize = 0x1000; //this option is ignored with SSH1 f.AgentForward = new AgentForwardClient(); Reader reader = new Reader(); //simple event receiver AuthenticationType at = AuthenticationType.Password; f.AuthenticationType = at; f.Password = password; //Creating a new SSH connection over the underlying socket _conn = SSHConnection.Connect(f, reader, s); reader._conn = _conn; //Opening a shell SSHChannel ch = _conn.OpenShell(reader); reader._pf = ch; while (!reader._ready) { Thread.Sleep(100); } Thread.Sleep(1000); ch.Transmit(Encoding.Default.GetBytes("ssh -A -l okajima localhost\r")); //Go to sample shell SampleShell(reader); }
public void ExecuteRemoteCommand(string command, Action <string> callback) { OutputCollectingReader r = new OutputCollectingReader(); r.callback = callback; m_outputParser.AddReader(r); SSHChannel chan = StartShell(r); r.chan = chan; // TODO This whole function probably ought to spin off a new thread or something while (!r._ready) { Thread.Sleep(50); } //chan.Transmit("bash"); string formattedCommand = string.Format("echo {0}; {1}; echo {2};exit;\r", StartToken, command, EndToken); chan.Transmit(formattedCommand); }
public static void Transmit(this SSHChannel chan, string text) { byte[] data = Encoding.Default.GetBytes(text); chan.Transmit(data, 0, data.Length); }
/// <summary> /// Sends data into tunnel /// </summary> public override void Write(byte[] buffer, int offset, int count) { m_Channel.Transmit(buffer, offset, count); }
public void Transmit(ByteDataFragment data) { _channel.Transmit(data.Buffer, data.Offset, data.Length); }
public void Transmit(string data) { _channel.Transmit(System.Text.ASCIIEncoding.ASCII.GetBytes(data), 0, data.Length); }