support for remote command execution;
authorwenzelm
Mon Oct 10 11:11:38 2016 +0200 (2016-10-10)
changeset 64129fce8b7c746b4
parent 64128 cc5ea4d648d8
child 64130 e17c211a0bb6
support for remote command execution;
tuned;
src/Pure/General/ssh.scala
     1.1 --- a/src/Pure/General/ssh.scala	Mon Oct 10 10:42:14 2016 +0200
     1.2 +++ b/src/Pure/General/ssh.scala	Mon Oct 10 11:11:38 2016 +0200
     1.3 @@ -73,6 +73,16 @@
     1.4    }
     1.5  
     1.6  
     1.7 +  /* remote command execution */
     1.8 +
     1.9 +  class Exec private [SSH](val session: Session, val channel: ChannelExec)
    1.10 +  {
    1.11 +    override def toString: String = "exec " + session.toString
    1.12 +
    1.13 +    def close { channel.disconnect }
    1.14 +  }
    1.15 +
    1.16 +
    1.17    /* session */
    1.18  
    1.19    class Session private[SSH](val session: JSch_Session)
    1.20 @@ -85,8 +95,14 @@
    1.21  
    1.22      def close { session.disconnect }
    1.23  
    1.24 -    def channel_exec: ChannelExec =
    1.25 -      session.openChannel("exec").asInstanceOf[ChannelExec]
    1.26 +    def exec(command: String, connect_timeout: Time = Time.seconds(60)): Exec =
    1.27 +    {
    1.28 +      val channel = session.openChannel("exec").asInstanceOf[ChannelExec]
    1.29 +      channel.setCommand(command)
    1.30 +      channel.connect(connect_timeout.ms.toInt)
    1.31 +
    1.32 +      new Exec(this, channel)
    1.33 +    }
    1.34  
    1.35      def channel_sftp: ChannelSftp =
    1.36        session.openChannel("sftp").asInstanceOf[ChannelSftp]
    1.37 @@ -110,8 +126,7 @@
    1.38        session.setConfig("compression_level", "9")
    1.39      }
    1.40  
    1.41 -    if (connect_timeout.is_zero) session.connect
    1.42 -    else session.connect(connect_timeout.ms.toInt)
    1.43 +    session.connect(connect_timeout.ms.toInt)
    1.44  
    1.45      new SSH.Session(session)
    1.46    }