Inheritance: OutputStream
Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public SshHelper(string Host, string UserName, string Password)
        {
            host = Host;
            var jsch = new JSch();
            session = jsch.getSession(UserName, host, 22);
            session.setPassword(Password);

            var config = new Hashtable { { "StrictHostKeyChecking", "no" } };
            session.setConfig(config);

            session.connect();

            channel = (ChannelShell)session.openChannel("shell");

            writer_po = new PipedOutputStream();
            var writer_pi = new PipedInputStream(writer_po);

            var reader_pi = new PipedInputStream();
            var 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);
        }
Exemplo n.º 3
0
			internal MyPipedInputStream(PipedOutputStream Out):base(Out) { }
Exemplo n.º 4
0
		public virtual Stream getOutputStream()  
		{
			PipedOutputStream Out=new PipedOutputStream();
			io.setInputStream(new PassiveInputStream(Out
				, 32*1024
				), false);
			//  io.setInputStream(new PassiveInputStream(Out), false);
			return Out;
		}
Exemplo n.º 5
0
 public override void close()
 {
     if(outs!=null){
     this.outs.close();
       }
       outs=null;
 }
Exemplo n.º 6
0
 internal PassiveInputStream(PipedOutputStream outs)
     : base(outs)
 {
     this.outs=outs;
 }
Exemplo n.º 7
0
        public Stream get(String src, SftpProgressMonitor monitor, int mode)
        {
            if(mode==RESUME)
            {
                throw new SftpException(SSH_FX_FAILURE, "faile to resume from "+src);
            }
            if(!src.StartsWith("/")){ src=cwd+"/"+src; }
            try
            {
                ArrayList v=glob_remote(src);
                if(v.Count!=1)
                {
                    throw new SftpException(SSH_FX_FAILURE, v.ToString());
                }
                src=(String)(v[0]);

                SftpATTRS attr=stat(src);

                PipedInputStream pis=new PipedInputStream();
                PipedOutputStream pos=new PipedOutputStream(pis);
                ChannelSftp channel=this;
                String _src=src;

                if(attr.getSize()<=0)
                {
                    try{ pos.Close(); }
                    catch{}//(Exception ee){}
                    return pis;
                }

                Exception[] closed=new Exception[1];
                closed[0]=null;
                runnable2 runnable2 = new runnable2(channel, pos, _src, monitor, mode, closed);
                (new Thread(new ThreadStart(runnable2.run))).Start();
                while(true)
                {
                    if(pis.available()!=0)break;
                    if(closed[0]!=null)
                    {
                        throw closed[0];
                    }
                    //	System.outs.println("pis wait");
                    Thread.Sleep(1000);
                }
                return pis;
            }
            catch(Exception e)
            {
                if(e is SftpException) throw (SftpException)e;
                throw new SftpException(SSH_FX_FAILURE, "");
            }
        }
Exemplo n.º 8
0
 /**
  * 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);
 }
Exemplo n.º 9
0
			internal PassiveInputStream(PipedOutputStream Out):base(Out) 
			{
				this.Out=Out;
			}
Exemplo n.º 10
0
		public PipedStream(PipedInputStream pins, PipedOutputStream pouts)
		{
			this.pins = pins;
			this.pouts = pouts;
		}
Exemplo n.º 11
0
		public override void start() 
		{ //throws JSchException{
			try
			{

				PipedOutputStream pos=new PipedOutputStream();
				io.setOutputStream(pos);
				PipedInputStream pis=new MyPipedInputStream(pos, 32*1024);
				io.setInputStream(pis);

				Request request=new RequestSftp();
				request.request(session, this);

				/*
					  System.err.println("lmpsize: "+lmpsize);
					  System.err.println("lwsize: "+lwsize);
					  System.err.println("rmpsize: "+rmpsize);
					  System.err.println("rwsize: "+rwsize);
				*/

				buf=new Buffer(rmpsize);
				packet=new Packet(buf);
				int i=0;
				int length;
				int type;
				byte[] str;

				// send SSH_FXP_INIT
				sendINIT();

				// receive SSH_FXP_VERSION
				Header _header=new Header();
				_header=header(buf, _header);
				length=_header.length;
				if(length > MAX_MSG_LENGTH)
				{
					throw new SftpException(SSH_FX_FAILURE, "Received message is too long: " + length);
				}
				type=_header.type;             // 2 -> SSH_FXP_VERSION
				server_version=_header.rid;
				skip(length);
				//System.err.println("SFTP protocol server-version="+server_version);
				//System.Console.WriteLine("server_version="+server_version+", type="+type+", length="+length+", i="+i);
				
				// send SSH_FXP_REALPATH
				sendREALPATH(new String(".").getBytes());

				// receive SSH_FXP_NAME
				_header=header(buf, _header);
				length=_header.length;
				type=_header.type;            // 104 -> SSH_FXP_NAME
				buf.rewind();
				fill(buf.buffer, 0, length);
				i=buf.getInt();              // count
				//System.Console.WriteLine("type="+type+", length="+length+", i="+i);
				str=buf.getString();         // filename
				//System.Console.WriteLine("str.length="+str.Length);
				home=cwd=new String(str);
				str=buf.getString();         // logname
				//    SftpATTRS.getATTR(buf);      // attrs

				lcwd=new File(".").getCanonicalPath();
			}
			catch(Exception e)
			{
				//System.out.println(e);
				//System.Console.WriteLine(e);
				if(e is JSchException) throw (JSchException)e;
				throw new JSchException(e.toString());
			}
		}
Exemplo n.º 12
0
            public InternalLocalPushConnection(TransportLocal transport)
                : base(transport)
            {
                Repository dst;
                try
                {
                    dst = new Repository(transport.remoteGitDir);
                }
                catch (IOException)
                {
                    throw new TransportException(uri, "Not a Git directory");
                }

                PipedInputStream in_r;
                PipedOutputStream in_w;

                PipedInputStream out_r;
                PipedOutputStream out_w;
                try
                {
                    in_r = new PipedInputStream();
                    in_w = new PipedOutputStream(in_r);

                    out_r = new PipedInputStream();
                    out_w = new PipedOutputStream(out_r);
                }
                catch (IOException ex)
                {
                    dst.Close();
                    throw new TransportException(uri, "Cannot connect pipes", ex);
                }

                worker = new Thread(() =>
                {
                    try
                    {
                        ReceivePack rp = new ReceivePack(dst);
                        rp.receive(out_r, in_w, null);
                    }
                    catch (IOException)
                    {
                        // Client side of the pipes should report the problem.
                    }
                    catch (Exception)
                    {
                        // Clients side will notice we went away, and report.
                    }
                    finally
                    {
                        try
                        {
                            out_r.close();
                        }
                        catch (IOException)
                        {
                            // Ignore close failure, we probably crashed above.
                        }

                        try
                        {
                            in_w.close();
                        }
                        catch (IOException)
                        {
                            // Ignore close failure, we probably crashed above.
                        }

                        dst.Close();
                    }
                });
                worker.Name = "JGit-Receive-Pack";
                worker.Start();

                init(in_r, out_w);
                readAdvertisedRefs();
            }
Exemplo n.º 13
0
 public PipedStream(PipedInputStream pins, PipedOutputStream pouts)
 {
     this.pins  = pins;
     this.pouts = pouts;
 }
Exemplo n.º 14
0
			internal MyPipedInputStream(PipedOutputStream Out, int size):base(Out) 
			{
				buffer=new byte[size];
			}
Exemplo n.º 15
0
        /**
         * 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);
        }
Exemplo n.º 16
0
			internal PassiveInputStream(PipedOutputStream Out, int size) :base(Out, size)
			{
				this.Out=Out;
			}
Exemplo n.º 17
0
        /**
         * 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);
        }
Exemplo n.º 18
0
			public override void close() 
			{
				if(Out!=null)
				{
					this.Out.close();
				}
				Out=null;
			}
Exemplo n.º 19
0
 public virtual Stream getOutputStream()
 {
     PipedOutputStream outs=new PipedOutputStream();
     io.setInputStream(new PassiveInputStream(outs));
     return outs;
 }
Exemplo n.º 20
0
 /**
  * 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);
 }
Exemplo n.º 21
0
        public override void start()
        {
            try
            {
                PipedOutputStream pos = new PipedOutputStream();

                io.setOutputStream(pos);

                PipedInputStream pis = new MyPipedInputStream(pos, 32 * 1024);

                io.setInputStream(pis);

                Request request = new RequestSftp();
                request.request(session, this);

                buf = new Buffer(rmpsize);
                packet = new Packet(buf);
                int i = 0;
                int length;
                int type;
                byte[] str;

                // send SSH_FXP_INIT
                sendINIT();

                // receive SSH_FXP_VERSION
                Header _header = new Header();
                _header = header(buf, _header);
                length = _header.length;

                if (length > MAX_MSG_LENGTH)
                {
                    throw new SftpException(SSH_FX_FAILURE, "Received message is too long: " + length);
                }

                type = _header.type; // 2 -> SSH_FXP_VERSION
                server_version = _header.rid;
                skip(length);

                // send SSH_FXP_REALPATH
                sendREALPATH(".".GetBytes());

                // receive SSH_FXP_NAME
                _header = header(buf, _header);
                length = _header.length;
                type = _header.type; // 104 -> SSH_FXP_NAME
                buf.rewind();
                fill(buf.buffer, 0, length);
                i = buf.getInt(); // count
                str = buf.getString(); // filename
                home = cwd = new JavaString(str);
                str = buf.getString(); // logname

                lcwd = new File(".").getCanonicalPath();
            }
            catch (Exception e)
            {
                if (e is JSchException) throw (JSchException)e;
                throw new JSchException(e);
            }
        }