public void request(Session session, Channel channel) { Buffer buf = new Buffer(); Packet packet = new Packet(buf); bool reply = waitForReply(); if (reply) { channel.Replay = -1; } packet.reset(); buf.putByte((byte)Session.SSH_MSG_CHANNEL_REQUEST); buf.putInt(channel.Recipient); buf.putString(Util.getBytes("subsystem")); buf.putByte((byte)(waitForReply() ? 1 : 0)); buf.putString(Util.getBytes("sftp")); session.write(packet); if (reply) { while (channel.Replay == -1) { try { System.Threading.Thread.Sleep(10); } catch//(Exception ee) { } } if (channel.Replay == 0) { throw new JSchException("failed to send sftp request"); } } }
public void request(Session session, Channel channel) { Buffer buf = new Buffer(); Packet packet = new Packet(buf); bool reply = waitForReply(); if (reply) channel.Replay = -1; packet.reset(); buf.putByte((byte)Session.SSH_MSG_CHANNEL_REQUEST); buf.putInt(channel.Recipient); buf.putString("subsystem"); buf.putByte((byte)(waitForReply() ? 1 : 0)); buf.putString(m_subsystem); session.write(packet); if (reply) { while (channel.Replay == -1) { try { Thread.sleep(10); } catch { } } if (channel.Replay == 0) throw new JSchException("failed to send subsystem request"); } }
public void request(Session session, Channel channel) { Buffer buf = new Buffer(); Packet packet = new Packet(buf); packet.reset(); buf.putByte((byte)Session.SSH_MSG_CHANNEL_REQUEST); buf.putInt(channel.Recipient); buf.putString(Util.getBytes("signal")); buf.putByte((byte)(waitForReply() ? 1 : 0)); buf.putString(Util.getBytes(m_signal)); session.write(packet); }
public void request(Session session, Channel channel) { Buffer buf = new Buffer(); Packet packet = new Packet(buf); // send // byte SSH_MSG_CHANNEL_REQUEST(98) // uint32 recipient channel // string request type // "shell" // boolean want reply // 0 packet.reset(); buf.putByte((byte)Session.SSH_MSG_CHANNEL_REQUEST); buf.putInt(channel.Recipient); buf.putString(Util.getBytes("shell")); buf.putByte((byte)(waitForReply() ? 1 : 0)); session.write(packet); }
public void request(Session session, Channel channel) { Packet packet = session.m_packet; Buffer buf = session.m_buf; // send // byte SSH_MSG_CHANNEL_REQUEST(98) // uint32 recipient channel // string request type // "exec" // boolean want reply // 0 // string command packet.reset(); buf.putByte((byte)Session.SSH_MSG_CHANNEL_REQUEST); buf.putInt(channel.Recipient); buf.putString("exec"); buf.putByte((byte)(waitForReply() ? 1 : 0)); buf.putString(m_command); session.write(packet); }
public void request(Session session, Channel channel) { Buffer buf = new Buffer(); Packet packet = new Packet(buf); //byte SSH_MSG_CHANNEL_REQUEST //uint32 recipient_channel //string "window-change" //boolean FALSE //uint32 terminal width, columns //uint32 terminal height, rows //uint32 terminal width, pixels //uint32 terminal height, pixels packet.reset(); buf.putByte((byte)Session.SSH_MSG_CHANNEL_REQUEST); buf.putInt(channel.Recipient); buf.putString(Util.getBytes("window-change")); buf.putByte((byte)(waitForReply() ? 1 : 0)); buf.putInt(m_width_columns); buf.putInt(m_height_rows); buf.putInt(m_width_pixels); buf.putInt(m_height_pixels); session.write(packet); }
internal void addChannel(Channel channel) { channel.Session = this; }
public void write(Packet packet, Channel c, int length) { while (true) { if (m_in_kex) { try { Thread.Sleep(10); } catch (ThreadInterruptedException) { } continue; } lock (c) { if (c.RemoteWindowSize >= length) { c.RemoteWindowSize -= length; break; } } if (c.IsClosed || !c.isConnected()) throw new IOException("channel is broken"); bool sendit = false; int s = 0; byte command = 0; int recipient = -1; lock (c) { if (c.RemoteWindowSize > 0) { int len = c.RemoteWindowSize; if (len > length) len = length; if (len != length) s = packet.shift(len, (m_c2smac != null ? m_c2smac.BlockSize : 0)); command = packet.m_buffer.m_buffer[5]; recipient = c.Recipient; length -= len; c.RemoteWindowSize -= len; sendit = true; } } if (sendit) { _write(packet); if (length == 0) return; packet.unshift(command, recipient, s, length); lock (c) { if (c.RemoteWindowSize >= length) { c.RemoteWindowSize -= length; break; } } } try { Thread.Sleep(100); } catch (ThreadInterruptedException) { } } _write(packet); }
public void request(Session session, Channel channel, string subsystem, bool want_reply) { m_subsystem = subsystem; m_want_reply = want_reply; request(session, channel); }
internal static void Remove(Channel channel) { lock (m_pool) { m_pool.Remove(channel); } }
internal static void disconnect(Session session) { Channel[] channels = null; int count = 0; lock (m_pool) { channels = new Channel[m_pool.Count]; for (int i = 0; i < m_pool.Count; i++) { try { Channel c = ((Channel)(m_pool[i])); if (c.m_session == session) channels[count++] = c; } catch (Exception) { } } } for (int i = 0; i < count; i++) channels[i].disconnect(); }
protected virtual void ConnectChannel() { m_channel = m_session.openChannel(ChannelType); OnChannelReceived(); m_channel.connect(); OnConnected(); }
/// <summary> /// Closes the SSH subsystem /// </summary> public virtual void Close() { if (m_channel != null) { m_channel.disconnect(); m_channel = null; } if (m_session != null) { m_session.disconnect(); m_session = null; } }
/// <summary> /// Connect a channel to the remote server using the 'SCP TO' command ('scp -t') /// </summary> /// <param name="channel">Will contain the new connected channel</param> /// <param name="server">Will contaun the new connected server I/O stream</param> /// <param name="rfile">The remote path on the server</param> /// <param name="recursive">Idicate a recursive scp transfer</param> protected void SCP_ConnectTo(out Channel channel, out Stream server, string rfile, bool recursive) { string scpCommand = "scp -p -t "; if (recursive) scpCommand += "-r "; scpCommand += "\"" + rfile + "\""; channel = (ChannelExec)m_session.openChannel(ChannelType); ((ChannelExec)channel).setCommand(scpCommand); server = new Streams.CombinedStream (channel.getInputStream(), channel.getOutputStream()); channel.connect(); SCP_CheckAck(server); }