示例#1
0
        /// <summary>
        /// Execute a command through the ssh session, pumping its
        /// stderr and stdout to our own logs.
        /// </summary>
        /// <exception cref="Com.Jcraft.Jsch.JSchException"/>
        /// <exception cref="System.Exception"/>
        /// <exception cref="System.IO.IOException"/>
        private int ExecCommand(Session session, string cmd)
        {
            Log.Debug("Running cmd: " + cmd);
            ChannelExec exec = null;

            try
            {
                exec = (ChannelExec)session.OpenChannel("exec");
                exec.SetCommand(cmd);
                exec.SetInputStream(null);
                exec.Connect();
                // Pump stdout of the command to our WARN logs
                StreamPumper outPumper = new StreamPumper(Log, cmd + " via ssh", exec.GetInputStream
                                                              (), StreamPumper.StreamType.Stdout);
                outPumper.Start();
                // Pump stderr of the command to our WARN logs
                StreamPumper errPumper = new StreamPumper(Log, cmd + " via ssh", exec.GetErrStream
                                                              (), StreamPumper.StreamType.Stderr);
                errPumper.Start();
                outPumper.Join();
                errPumper.Join();
                return(exec.GetExitStatus());
            }
            finally
            {
                Cleanup(exec);
            }
        }
示例#2
0
        protected ChannelExec GetChannelExec(string command)
        {
            ChannelExec exeChannel = (ChannelExec)m_session.openChannel("exec");

            exeChannel.setCommand(command);
            return(exeChannel);
        }
示例#3
0
 /// <exception cref="NGit.Errors.TransportException"></exception>
 internal override void Exec(string commandName)
 {
     this._enclosing.InitSession();
     try
     {
         this.channel = (ChannelExec)this._enclosing.sock.OpenChannel("exec");
         this.channel.SetCommand(this._enclosing.CommandFor(commandName));
     }
     catch (JSchException je)
     {
         throw new TransportException(this._enclosing.uri, je.Message, je);
     }
 }
示例#4
0
 private static void Cleanup(ChannelExec exec)
 {
     if (exec != null)
     {
         try
         {
             exec.Disconnect();
         }
         catch (Exception t)
         {
             Log.Warn("Couldn't disconnect ssh channel", t);
         }
     }
 }
 protected override void RunOperations()
 {
     try {
         channel = Ssh.GetChannel(command);
         channel.setErrStream(new TextStream(stdErr));
         channel.setOutputStream(new TextStream(stdOut));
         channel.connect();
         while (!channel.isEOF())
         {
             Thread.Sleep(200);
         }
         channel.disconnect();
     } finally {
         ExitCode = channel.getExitStatus();
     }
 }
示例#6
0
 internal override void Close()
 {
     if (this.channel != null)
     {
         try
         {
             this.exitStatus = this.channel.GetExitStatus();
             if (this.channel.IsConnected())
             {
                 this.channel.Disconnect();
             }
         }
         finally
         {
             this.channel = null;
         }
     }
 }
示例#7
0
            public override void Close()
            {
                base.Close();

                if (_channel != null)
                {
                    try
                    {
                        if (_channel.isConnected())
                        {
                            _channel.disconnect();
                        }
                    }
                    finally
                    {
                        _channel = null;
                    }
                }
            }
 /// <summary>
 /// Opens a channel on the session ("sock") for executing the given
 /// command, opens streams, and starts command execution.
 /// </summary>
 /// <remarks>
 /// Opens a channel on the session ("sock") for executing the given
 /// command, opens streams, and starts command execution.
 /// </remarks>
 /// <param name="commandName">the command to execute</param>
 /// <param name="tms">the timeout value, in seconds, for the command.</param>
 /// <exception cref="NGit.Errors.TransportException">
 /// on problems opening a channel or connecting to the remote
 /// host
 /// </exception>
 /// <exception cref="System.IO.IOException">on problems opening streams</exception>
 public JschProcess(JschSession _enclosing, string commandName, int tms)
 {
     this._enclosing = _enclosing;
     this.timeout    = tms;
     try
     {
         this.channel = (ChannelExec)this._enclosing.sock.OpenChannel("exec");
         this.channel.SetCommand(commandName);
         this.SetupStreams();
         this.channel.Connect(this.timeout > 0 ? this.timeout * 1000 : 0);
         if (!this.channel.IsConnected())
         {
             throw new TransportException(this._enclosing.uri, "connection failed");
         }
     }
     catch (JSchException e)
     {
         throw new TransportException(this._enclosing.uri, e.Message, e);
     }
 }
            public override void Close()
            {
                base.Close();

                if (_channel == null)
                {
                    return;
                }

                try
                {
                    _exitStatus = _channel.getExitStatus();
                    if (_channel.isConnected())
                    {
                        _channel.disconnect();
                    }
                }
                finally
                {
                    _channel = null;
                }
            }
            public SshPushConnection(TransportGitSsh instance)
                : base(instance)
            {
                try
                {
                    _channel = instance.Exec(instance.OptionReceivePack);

                    if (_channel.isConnected())
                    {
                        init(_channel.getInputStream(), _channel.getOutputStream());
                    }
                    else
                    {
                        throw new TransportException(uri, instance._errStream.ToString());
                    }
                }
                catch (TransportException)
                {
                    Close();
                    throw;
                }
                catch (SocketException err)
                {
                    Close();
                    throw new TransportException(uri, "remote hung up unexpectedly", err);
                }

                try
                {
                    readAdvertisedRefs();
                }
                catch (NoRemoteRepositoryException notFound)
                {
                    Close();
                    instance.checkExecFailure(_exitStatus, instance.OptionReceivePack);
                    throw instance.cleanNotFound(notFound);
                }
            }