public void setX11Host(JavaString host) { ChannelX11.setHost(host); }
internal void setUserName(JavaString foo) { this.username = foo; }
public void setPortForwardingR(int rport, JavaString daemon, Object[] arg) { ChannelForwardedTCPIP.addPort(this, rport, daemon, arg); setPortForwarding(rport); }
public void setX11Cookie(JavaString cookie) { ChannelX11.setCookie(cookie); }
public void setPortForwardingR(int rport, JavaString host, int lport, SocketFactory sf) { ChannelForwardedTCPIP.addPort(this, rport, host, lport, sf); setPortForwarding(rport); }
public void setPortForwardingR(int rport, JavaString daemon) { setPortForwardingR(rport, daemon, null); }
public void setPortForwardingL(JavaString boundaddress, int lport, JavaString host, int rport, ServerSocketFactory ssf) { PortWatcher pw = PortWatcher.addPort(this, boundaddress, lport, host, rport, ssf); JavaThread tmp = new JavaThread(pw); tmp.Name("PortWatcher Thread for " + host); tmp.Start(); }
public ArrayList ls(String path) { path = remoteAbsolutePath(path); String dir = path; byte[] pattern = null; SftpATTRS attr = null; if (isPattern(dir) || ((attr = stat(dir)) != null && !attr.isDir())) { int foo = path.LastIndexOf('/'); dir = path.Substring(0, ((foo == 0) ? 1 : foo)); pattern = path.Substring(foo + 1).GetBytes(); } sendOPENDIR(dir.GetBytes()); Header _header = new Header(); _header = header(buf, _header); int length = _header.length; int type = _header.type; buf.rewind(); fill(buf.buffer, 0, length); if (type != SSH_FXP_STATUS && type != SSH_FXP_HANDLE) { throw new SftpException(SSH_FX_FAILURE, ""); } if (type == SSH_FXP_STATUS) { int i = buf.getInt(); throwStatusError(buf, i); } byte[] handle = buf.getString(); // filename ArrayList v = new ArrayList(); while (true) { sendREADDIR(handle); _header = header(buf, _header); length = _header.length; type = _header.type; if (type != SSH_FXP_STATUS && type != SSH_FXP_NAME) { throw new SftpException(SSH_FX_FAILURE, ""); } if (type == SSH_FXP_STATUS) { buf.rewind(); fill(buf.buffer, 0, length); int i = buf.getInt(); if (i == SSH_FX_EOF) break; throwStatusError(buf, i); } buf.rewind(); fill(buf.buffer, 0, 4); length -= 4; int count = buf.getInt(); byte[] str; buf.reset(); while (count > 0) { if (length > 0) { buf.shift(); int j = (buf.buffer.Length > (buf.index + length)) ? length : (buf.buffer.Length - buf.index); int i = fill(buf.buffer, buf.index, j); buf.index += i; length -= i; } byte[] filename = buf.getString(); str = buf.getString(); String longname = new JavaString(str); SftpATTRS attrs = SftpATTRS.getATTR(buf); if (pattern == null || Util.glob(pattern, filename)) { v.Add(new LsEntry(new JavaString(filename), path, longname, attrs)); } count--; } } _sendCLOSE(handle, _header); return v; }
public void setPortForwardingL(int lport, JavaString host, int rport) { setPortForwardingL("127.0.0.1", lport, host, rport); }
public void setPortForwardingL(JavaString boundaddress, int lport, JavaString host, int rport) { setPortForwardingL(boundaddress, lport, host, rport, null); }
public void setPassword(JavaString foo) { this.password = foo; }
public void setHost(JavaString host) { this.host = host; }
public void setClientVersion(JavaString cv) { V_C = cv.GetBytes(); }
public void delPortForwardingL(JavaString boundaddress, int lport) { PortWatcher.delPort(this, boundaddress, lport); }
public void setPortForwardingR(int rport, JavaString host, int lport) { setPortForwardingR(rport, host, lport, (SocketFactory)null); }
public void run() { thread = this; byte[] foo; Buffer buf = new Buffer(); Packet packet = new Packet(buf); int i = 0; Channel channel; int[] start = new int[1]; int[] length = new int[1]; KeyExchange kex = null; try { while (_isConnected && thread != null) { buf = read(buf); int msgType = buf.buffer[5] & 0xff; if (kex != null && kex.getState() == msgType) { bool result = kex.next(buf); if (!result) { throw new JSchException("verify: " + result); } continue; } switch (msgType) { case SSH_MSG_KEXINIT: //System.Console.WriteLine("KEXINIT"); kex = receive_kexinit(buf); break; case SSH_MSG_NEWKEYS: //System.Console.WriteLine("NEWKEYS"); send_newkeys(); receive_newkeys(buf, kex); kex = null; break; case SSH_MSG_CHANNEL_DATA: buf.getInt(); buf.getByte(); buf.getByte(); i = buf.getInt(); channel = Channel.getChannel(i, this); foo = buf.getString(start, length); if (channel == null) { break; } try { channel.write(foo, start[0], length[0]); } catch (Exception) { //System.Console.WriteLine(e); try { channel.disconnect(); } catch (Exception) { } break; } int len = length[0]; channel.setLocalWindowSize(channel.lwsize - len); if (channel.lwsize < channel.lwsize_max / 2) { packet.reset(); buf.putByte((byte)SSH_MSG_CHANNEL_WINDOW_ADJUST); buf.putInt(channel.getRecipient()); buf.putInt(channel.lwsize_max - channel.lwsize); write(packet); channel.setLocalWindowSize(channel.lwsize_max); } break; case SSH_MSG_CHANNEL_EXTENDED_DATA: buf.getInt(); buf.getShort(); i = buf.getInt(); channel = Channel.getChannel(i, this); buf.getInt(); // data_type_code == 1 foo = buf.getString(start, length); //System.Console.WriteLine("stderr: "+new String(foo,start[0],length[0])); if (channel == null) { break; } //channel.write(foo, start[0], length[0]); channel.write_ext(foo, start[0], length[0]); len = length[0]; channel.setLocalWindowSize(channel.lwsize - len); if (channel.lwsize < channel.lwsize_max / 2) { packet.reset(); buf.putByte((byte)SSH_MSG_CHANNEL_WINDOW_ADJUST); buf.putInt(channel.getRecipient()); buf.putInt(channel.lwsize_max - channel.lwsize); write(packet); channel.setLocalWindowSize(channel.lwsize_max); } break; case SSH_MSG_CHANNEL_WINDOW_ADJUST: buf.getInt(); buf.getShort(); i = buf.getInt(); channel = Channel.getChannel(i, this); if (channel == null) { break; } channel.addRemoteWindowSize(buf.getInt()); break; case SSH_MSG_CHANNEL_EOF: buf.getInt(); buf.getShort(); i = buf.getInt(); channel = Channel.getChannel(i, this); if (channel != null) { //channel._eof_remote=true; //channel.eof(); channel.eof_remote(); } /* packet.reset(); buf.putByte((byte)SSH_MSG_CHANNEL_EOF); buf.putInt(channel.getRecipient()); write(packet); */ break; case SSH_MSG_CHANNEL_CLOSE: buf.getInt(); buf.getShort(); i = buf.getInt(); channel = Channel.getChannel(i, this); if (channel != null) { // channel.close(); channel.disconnect(); } /* if(Channel.pool.Count==0){ thread=null; } */ break; case SSH_MSG_CHANNEL_OPEN_CONFIRMATION: buf.getInt(); buf.getShort(); i = buf.getInt(); channel = Channel.getChannel(i, this); if (channel == null) { //break; } channel.setRecipient(buf.getInt()); channel.setRemoteWindowSize(buf.getInt()); channel.setRemotePacketSize(buf.getInt()); break; case SSH_MSG_CHANNEL_OPEN_FAILURE: buf.getInt(); buf.getShort(); i = buf.getInt(); channel = Channel.getChannel(i, this); if (channel == null) { //break; } int reason_code = buf.getInt(); //foo=buf.getString(); // additional textual information //foo=buf.getString(); // language tag channel.exitstatus = reason_code; channel._close = true; channel._eof_remote = true; channel.setRecipient(0); break; case SSH_MSG_CHANNEL_REQUEST: buf.getInt(); buf.getShort(); i = buf.getInt(); foo = buf.getString(); bool reply = (buf.getByte() != 0); channel = Channel.getChannel(i, this); if (channel != null) { byte reply_type = (byte)SSH_MSG_CHANNEL_FAILURE; if ((new JavaString(foo)).Equals("exit-status")) { i = buf.getInt(); // exit-status channel.setExitStatus(i); // System.Console.WriteLine("exit-stauts: "+i); // channel.close(); reply_type = (byte)SSH_MSG_CHANNEL_SUCCESS; } if (reply) { packet.reset(); buf.putByte(reply_type); buf.putInt(channel.getRecipient()); write(packet); } } else { } break; case SSH_MSG_CHANNEL_OPEN: buf.getInt(); buf.getShort(); foo = buf.getString(); JavaString ctyp = new JavaString(foo); //System.Console.WriteLine("type="+ctyp); if (!new JavaString("forwarded-tcpip").Equals(ctyp) && !(new JavaString("x11").Equals(ctyp) && x11_forwarding)) { Console.WriteLine("Session.run: CHANNEL OPEN " + ctyp); throw new IOException("Session.run: CHANNEL OPEN " + ctyp); } else { channel = Channel.getChannel(ctyp); addChannel(channel); channel.getData(buf); channel.init(); packet.reset(); buf.putByte((byte)SSH_MSG_CHANNEL_OPEN_CONFIRMATION); buf.putInt(channel.getRecipient()); buf.putInt(channel.id); buf.putInt(channel.lwsize); buf.putInt(channel.lmpsize); write(packet); JavaThread tmp = new JavaThread(channel); tmp.Name("Channel " + ctyp + " " + host); tmp.Start(); break; } case SSH_MSG_CHANNEL_SUCCESS: buf.getInt(); buf.getShort(); i = buf.getInt(); channel = Channel.getChannel(i, this); if (channel == null) { break; } channel.reply = 1; break; case SSH_MSG_CHANNEL_FAILURE: buf.getInt(); buf.getShort(); i = buf.getInt(); channel = Channel.getChannel(i, this); if (channel == null) { break; } channel.reply = 0; break; case SSH_MSG_GLOBAL_REQUEST: buf.getInt(); buf.getShort(); foo = buf.getString(); // request name reply = (buf.getByte() != 0); if (reply) { packet.reset(); buf.putByte((byte)SSH_MSG_REQUEST_FAILURE); write(packet); } break; case SSH_MSG_REQUEST_FAILURE: case SSH_MSG_REQUEST_SUCCESS: JavaThread t = grr.getThread(); if (t != null) { grr.setReply(msgType == SSH_MSG_REQUEST_SUCCESS ? 1 : 0); t.Interrupt(); } break; default: Console.WriteLine("Session.run: unsupported type " + msgType); throw new IOException("Unknown SSH message type " + msgType); } } } catch (Exception) { //System.Console.WriteLine("# Session.run"); //e.printStackTrace(); } try { disconnect(); } catch (NullReferenceException) { //System.Console.WriteLine("@1"); //e.printStackTrace(); } catch (Exception) { //System.Console.WriteLine("@2"); //e.printStackTrace(); } _isConnected = false; }
/* cd /tmp c->s REALPATH s->c NAME c->s STAT s->c ATTR */ public void cd(String path) { try { path = remoteAbsolutePath(path); ArrayList v = glob_remote(path); if (v.Count != 1) { throw new SftpException(SSH_FX_FAILURE, v.ToString()); } path = (String)(v[0]); sendREALPATH(path.GetBytes()); Header _header = new Header(); _header = header(buf, _header); int length = _header.length; int type = _header.type; buf.rewind(); fill(buf.buffer, 0, length); if (type != 101 && type != 104) { throw new SftpException(SSH_FX_FAILURE, ""); } int i; if (type == 101) { i = buf.getInt(); throwStatusError(buf, i); } i = buf.getInt(); byte[] str = buf.getString(); if (str != null && str[0] != '/') { str = (cwd + "/" + new JavaString(str)).GetBytes(); } str = buf.getString(); // logname i = buf.getInt(); // attrs String newpwd = new JavaString(str); SftpATTRS attr = GetPathAttributes(newpwd); if ((attr.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS) == 0) { throw new SftpException(SSH_FX_FAILURE, "Can't change directory: " + path); } if (!attr.isDir()) { throw new SftpException(SSH_FX_FAILURE, "Can't change directory: " + path); } cwd = newpwd; } catch (Exception e) { if (e is SftpException) throw (SftpException)e; throw new SftpException(SSH_FX_FAILURE, ""); } }