public virtual void connect() { if (!session.isConnected()) { throw new SshClientException("session is down"); } try { Buffer buf = new Buffer(100); Packet packet = new Packet(buf); // send // byte SSH_MSG_CHANNEL_OPEN(90) // string channel type // // uint32 sender channel // 0 // uint32 initial window size // 0x100000(65536) // uint32 maxmum packet size // 0x4000(16384) packet.reset(); buf.putByte((byte)90); buf.putString(this.type); buf.putInt(this.id); buf.putInt(this.lwsize); buf.putInt(this.lmpsize); session.write(packet); int retry = 1000; while (this.getRecipient() == -1 && session.isConnected() && retry > 0) { try { ThreadAux.Sleep(50); } catch (Exception) { } retry--; } if (!session.isConnected()) { throw new SshClientException("session is down"); } if (retry == 0) { throw new SshClientException("channel is not opened."); } connected = true; start(); } catch (Exception e) { connected = false; if (e is SshClientException) { throw (SshClientException)e; } } }
public void request(Session session, AChannel channel) { Buffer buf = new Buffer(); Packet packet = new Packet(buf); bool reply = waitForReply(); if (reply) { channel.reply = -1; } packet.reset(); buf.putByte((byte)Session.SSH_MSG_CHANNEL_REQUEST); buf.putInt(channel.getRecipient()); buf.putString(StringAux.getBytesUTF8("subsystem")); buf.putByte((byte)(waitForReply() ? 1 : 0)); buf.putString(StringAux.getBytesUTF8(subsystem)); session.write(packet); if (reply) { while (channel.reply == -1) { try { ThreadAux.Sleep(10); } catch (System.Exception) { } } if (channel.reply == 0) { throw new SshClientException("failed to send subsystem request"); } } }
public override void connect() { try { if (!session.isConnected()) { throw new SshClientException("session is down"); } Buffer buf = new Buffer(150); Packet packet = new Packet(buf); // send // byte SSH_MSG_CHANNEL_OPEN(90) // string channel type // // uint32 sender channel // 0 // uint32 initial window size // 0x100000(65536) // uint32 maxmum packet size // 0x4000(16384) packet.reset(); buf.putByte((byte)90); buf.putString(StringAux.getBytes("direct-tcpip")); buf.putInt(id); buf.putInt(lwsize); buf.putInt(lmpsize); buf.putString(StringAux.getBytes(host)); buf.putInt(port); buf.putString(StringAux.getBytes(originator_IP_address)); buf.putInt(originator_port); session.write(packet); int retry = 1000; try { while (this.getRecipient() == -1 && session.isConnected() && retry > 0 && !_eof_remote) { //Thread.sleep(500); ThreadAux.Sleep(50); retry--; } } catch { } if (!session.isConnected()) { throw new SshClientException("session is down"); } if (retry == 0 || this._eof_remote) { throw new SshClientException("channel is not opened."); } /* * if(this.eof_remote){ // failed to open * disconnect(); * return; * } */ connected = true; thread = new ThreadAux(this); thread.start(); } catch (Exception e) { io.close(); io = null; AChannel.del(this); if (e is SshClientException) { throw (SshClientException)e; } } }