public SshHelper(string host, string username, string password) { this.host = host; JSch jsch=new JSch(); Session session=jsch.getSession(username, host, 22); session.setPassword( password ); Hashtable config=new Hashtable(); config.Add("StrictHostKeyChecking", "no"); session.setConfig(config); session.connect(); channel=(ChannelShell)session.openChannel("shell"); writer_po = new PipedOutputStream(); PipedInputStream writer_pi = new PipedInputStream( writer_po ); PipedInputStream reader_pi = new PipedInputStream(); PipedOutputStream reader_po = new PipedOutputStream( reader_pi ); reader = new StreamReader (reader_pi,Encoding.UTF8); channel.setInputStream( writer_pi ); channel.setOutputStream( reader_po ); channel.connect(); channel.setPtySize(132, 132, 1024, 768); }
public override void close() { if(Out!=null) { this.Out.close(); } Out=null; }
internal PassiveInputStream(PipedOutputStream Out) : base(Out) { this.Out=Out; }
internal PassiveInputStream(PipedOutputStream Out, int size) : base(Out, size) { this.Out=Out; }
internal MyPipedInputStream(PipedOutputStream Out, int size) : base(Out) { buffer=new byte[size]; }
internal MyPipedInputStream(PipedOutputStream Out) : base(Out) { }
public virtual Stream getOutputStream() { PipedOutputStream Out=new PipedOutputStream(); io.setInputStream(new PassiveInputStream(Out , 32*1024 ), false); // io.setInputStream(new PassiveInputStream(Out), false); return Out; }
/** * Causes this piped input stream to be connected * to the piped output stream <code>src</code>. * If this object is already connected to some * other piped output stream, an <code>IOException</code> * is thrown. * <p> * If <code>src</code> is an * unconnected piped output stream and <code>snk</code> * is an unconnected piped input stream, they * may be connected by either the call: * <p> * <pre><code>snk.connect(src)</code> </pre> * <p> * or the call: * <p> * <pre><code>src.connect(snk)</code> </pre> * <p> * The two * calls have the same effect. * * @param src The piped output stream to connect to. * @exception IOException if an I/O error occurs. */ public virtual void connect(PipedOutputStream src) { src.connect(this); }
/** * Creates a <code>PipedInputStream</code> so * that it is connected to the piped output * stream <code>src</code>. Data bytes written * to <code>src</code> will then be available * as input from this stream. * * @param src the stream to connect to. * @exception IOException if an I/O error occurs. */ public PipedInputStream(PipedOutputStream src) { connect(src); }
public override void start() { try { PipedOutputStream pos=new PipedOutputStream(); io.setOutputStream(pos); // PipedInputStream pis=new PipedInputStream(pos); PipedInputStream pis=new MyPipedInputStream(pos, 32*1024); io.setInputStream(pis); Request request=new RequestSftp(); request.request(session, this); // thread=Thread.currentThread(); // buf=new Buffer(); buf=new Buffer(rmpsize); packet=new Packet(buf); int i=0; int j=0; int length; int type; byte[] str; // send SSH_FXP_INIT sendINIT(); // receive SSH_FXP_VERSION buf.rewind(); i=io.ins.Read(buf.buffer, 0, buf.buffer.Length); //System.out.println(io+" "+io.ins+" "+io.out); length=buf.getInt(); type=buf.getByte(); // 2 -> SSH_FXP_VERSION server_version=buf.getInt(); //System.out.println("SFTP protocol server-version="+server_version); // send SSH_FXP_REALPATH sendREALPATH(Util.getBytes(".")); // receive SSH_FXP_NAME buf.rewind(); i=io.ins.Read(buf.buffer, 0, buf.buffer.Length); length=buf.getInt(); type=buf.getByte(); // 104 -> SSH_FXP_NAME buf.getInt(); // i=buf.getInt(); // count str=buf.getString(); // filename home=cwd=Util.getString(str); str=buf.getString(); // logname // SftpATTRS.getATTR(buf); // attrs lcwd=Path.GetFullPath("."); //thread=new Thread(this); //thread.setName("Sftp for "+session.host); //thread.start(); } catch(Exception e) { //System.out.println(e); if(e is JSchException) throw (JSchException)e; throw new JSchException(e.ToString()); } }