src/Pure/General/ssh.scala
changeset 64141 79cd4be708fb
parent 64137 e9b3d9c1bc5a
child 64142 954451356017
equal deleted inserted replaced
64140:96d398871124 64141:79cd4be708fb
    15   OpenSSHConfig, UserInfo, Channel => JSch_Channel, ChannelExec, ChannelSftp, SftpATTRS}
    15   OpenSSHConfig, UserInfo, Channel => JSch_Channel, ChannelExec, ChannelSftp, SftpATTRS}
    16 
    16 
    17 
    17 
    18 object SSH
    18 object SSH
    19 {
    19 {
       
    20   /* user@host syntax */
       
    21 
       
    22   object User_Host
       
    23   {
       
    24     val Pattern = "^([^@]+)@(.+)$".r
       
    25 
       
    26     def parse(s: String): (String, String) =
       
    27       s match {
       
    28         case Pattern(user, host) => (user, host)
       
    29         case _ => ("", s)
       
    30       }
       
    31 
       
    32     def unapplySeq(s: String): Option[List[String]] =
       
    33     {
       
    34       val (user, host) = parse(s)
       
    35       Some(List(user, host))
       
    36     }
       
    37   }
       
    38 
       
    39 
    20   /* init */
    40   /* init */
    21 
    41 
    22   def init(options: Options): SSH =
    42   def init(options: Options): SSH =
    23   {
    43   {
    24     val config_dir = Path.explode(options.string("ssh_config_dir"))
    44     val config_dir = Path.explode(options.string("ssh_config_dir"))
   295   }
   315   }
   296 }
   316 }
   297 
   317 
   298 class SSH private(val options: Options, val jsch: JSch)
   318 class SSH private(val options: Options, val jsch: JSch)
   299 {
   319 {
   300   def open_session(host: String, port: Int = 22, user: String = null): SSH.Session =
   320   def open_session(host: String, port: Int = 22, user: String = ""): SSH.Session =
   301   {
   321   {
   302     val session = jsch.getSession(user, host, port)
   322     val session = jsch.getSession(if (user == "") null else user, host, port)
   303 
   323 
   304     session.setUserInfo(SSH.No_User_Info)
   324     session.setUserInfo(SSH.No_User_Info)
   305     session.setConfig("MaxAuthTries", "3")
   325     session.setConfig("MaxAuthTries", "3")
   306 
   326 
   307     if (options.bool("ssh_compression")) {
   327     if (options.bool("ssh_compression")) {