author | wenzelm |
Tue, 11 Oct 2016 10:21:32 +0200 | |
changeset 64141 | 79cd4be708fb |
parent 64137 | e9b3d9c1bc5a |
child 64142 | 954451356017 |
permissions | -rw-r--r-- |
64123 | 1 |
/* Title: Pure/General/ssh.scala |
2 |
Author: Makarius |
|
3 |
||
64124 | 4 |
SSH client based on JSch (see also http://www.jcraft.com/jsch/examples). |
64123 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
64134
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
10 |
import java.io.{InputStream, OutputStream, ByteArrayOutputStream} |
64131 | 11 |
|
64134
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
12 |
import scala.collection.{mutable, JavaConversions} |
64131 | 13 |
|
64123 | 14 |
import com.jcraft.jsch.{JSch, Logger => JSch_Logger, Session => JSch_Session, |
64132 | 15 |
OpenSSHConfig, UserInfo, Channel => JSch_Channel, ChannelExec, ChannelSftp, SftpATTRS} |
64123 | 16 |
|
17 |
||
18 |
object SSH |
|
19 |
{ |
|
64141 | 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 |
||
64123 | 40 |
/* init */ |
41 |
||
64130 | 42 |
def init(options: Options): SSH = |
64123 | 43 |
{ |
64130 | 44 |
val config_dir = Path.explode(options.string("ssh_config_dir")) |
64123 | 45 |
if (!config_dir.is_dir) error("Bad ssh config directory: " + config_dir) |
46 |
||
47 |
val jsch = new JSch |
|
48 |
||
64130 | 49 |
val config_file = Path.explode(options.string("ssh_config_file")) |
64123 | 50 |
if (config_file.is_file) |
51 |
jsch.setConfigRepository(OpenSSHConfig.parseFile(File.platform_path(config_file))) |
|
52 |
||
53 |
val known_hosts = config_dir + Path.explode("known_hosts") |
|
54 |
if (!known_hosts.is_file) known_hosts.file.createNewFile |
|
55 |
jsch.setKnownHosts(File.platform_path(known_hosts)) |
|
56 |
||
64130 | 57 |
val identity_files = |
58 |
Library.space_explode(':', options.string("ssh_identity_files")).map(Path.explode(_)) |
|
64123 | 59 |
for (identity_file <- identity_files if identity_file.is_file) |
60 |
jsch.addIdentity(File.platform_path(identity_file)) |
|
61 |
||
64130 | 62 |
new SSH(options, jsch) |
64123 | 63 |
} |
64 |
||
64130 | 65 |
def connect_timeout(options: Options): Int = |
66 |
options.seconds("ssh_connect_timeout").ms.toInt |
|
67 |
||
64123 | 68 |
|
69 |
/* logging */ |
|
70 |
||
71 |
def logging(verbose: Boolean = true, debug: Boolean = false) |
|
72 |
{ |
|
73 |
JSch.setLogger(if (verbose) new Logger(debug) else null) |
|
74 |
} |
|
75 |
||
76 |
private class Logger(debug: Boolean) extends JSch_Logger |
|
77 |
{ |
|
78 |
def isEnabled(level: Int): Boolean = level != JSch_Logger.DEBUG || debug |
|
79 |
||
80 |
def log(level: Int, msg: String) |
|
81 |
{ |
|
82 |
level match { |
|
83 |
case JSch_Logger.ERROR | JSch_Logger.FATAL => Output.error_message(msg) |
|
84 |
case JSch_Logger.WARN => Output.warning(msg) |
|
85 |
case _ => Output.writeln(msg) |
|
86 |
} |
|
87 |
} |
|
88 |
} |
|
89 |
||
90 |
||
64128 | 91 |
/* user info */ |
92 |
||
93 |
object No_User_Info extends UserInfo |
|
94 |
{ |
|
95 |
def getPassphrase: String = null |
|
96 |
def getPassword: String = null |
|
97 |
def promptPassword(msg: String): Boolean = false |
|
98 |
def promptPassphrase(msg: String): Boolean = false |
|
99 |
def promptYesNo(msg: String): Boolean = false |
|
100 |
def showMessage(msg: String): Unit = Output.writeln(msg) |
|
101 |
} |
|
102 |
||
103 |
||
64132 | 104 |
/* channel */ |
64129 | 105 |
|
64134
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
106 |
class Channel[C <: JSch_Channel] private[SSH]( |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
107 |
val session: Session, val kind: String, val options: Options, val channel: C) |
64129 | 108 |
{ |
64130 | 109 |
override def toString: String = kind + " " + session.toString |
64129 | 110 |
|
111 |
def close { channel.disconnect } |
|
112 |
} |
|
113 |
||
64132 | 114 |
|
115 |
/* exec channel */ |
|
116 |
||
64134
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
117 |
private val exec_wait_delay = Time.seconds(0.3) |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
118 |
|
64131 | 119 |
class Exec private[SSH]( |
64134
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
120 |
session: Session, kind: String, options: Options, channel: ChannelExec) |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
121 |
extends Channel[ChannelExec](session, kind, options, channel) |
64131 | 122 |
{ |
123 |
def kill(signal: String) { channel.sendSignal(signal) } |
|
64134
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
124 |
|
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
125 |
val exit_status: Future[Int] = |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
126 |
Future.thread("ssh_wait") { |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
127 |
while (!channel.isClosed) Thread.sleep(exec_wait_delay.ms) |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
128 |
channel.getExitStatus |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
129 |
} |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
130 |
|
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
131 |
val stdin: OutputStream = channel.getOutputStream |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
132 |
val stdout: InputStream = channel.getInputStream |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
133 |
val stderr: InputStream = channel.getErrStream |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
134 |
|
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
135 |
// after preparing streams |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
136 |
channel.connect(connect_timeout(options)) |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
137 |
|
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
138 |
def result( |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
139 |
progress_stdout: String => Unit = (_: String) => (), |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
140 |
progress_stderr: String => Unit = (_: String) => (), |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
141 |
strict: Boolean = true): Process_Result = |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
142 |
{ |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
143 |
stdin.close |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
144 |
|
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
145 |
def read_lines(stream: InputStream, progress: String => Unit): List[String] = |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
146 |
{ |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
147 |
val result = new mutable.ListBuffer[String] |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
148 |
val line_buffer = new ByteArrayOutputStream(100) |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
149 |
def line_flush() |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
150 |
{ |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
151 |
val line = line_buffer.toString(UTF8.charset_name) |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
152 |
progress(line) |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
153 |
result += line |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
154 |
line_buffer.reset |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
155 |
} |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
156 |
|
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
157 |
var c = 0 |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
158 |
var finished = false |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
159 |
while (!finished) { |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
160 |
while ({ c = stream.read; c != -1 && c != 10 }) line_buffer.write(c) |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
161 |
if (c == 10) line_flush() |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
162 |
else if (channel.isClosed) { |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
163 |
if (line_buffer.size > 0) line_flush() |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
164 |
finished = true |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
165 |
} |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
166 |
else Thread.sleep(exec_wait_delay.ms) |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
167 |
} |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
168 |
|
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
169 |
result.toList |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
170 |
} |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
171 |
|
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
172 |
val out_lines = Future.thread("ssh_stdout") { read_lines(stdout, progress_stdout) } |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
173 |
val err_lines = Future.thread("ssh_stderr") { read_lines(stderr, progress_stderr) } |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
174 |
|
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
175 |
def terminate() |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
176 |
{ |
64136 | 177 |
close |
64134
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
178 |
out_lines.join |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
179 |
err_lines.join |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
180 |
exit_status.join |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
181 |
} |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
182 |
|
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
183 |
val rc = |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
184 |
try { exit_status.join } |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
185 |
catch { case Exn.Interrupt() => terminate(); Exn.Interrupt.return_code } |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
186 |
|
64136 | 187 |
close |
64134
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
188 |
if (strict && rc == Exn.Interrupt.return_code) throw Exn.Interrupt() |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
189 |
|
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
190 |
Process_Result(rc, out_lines.join, err_lines.join) |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
191 |
} |
64131 | 192 |
} |
193 |
||
194 |
||
64132 | 195 |
/* Sftp channel */ |
196 |
||
197 |
type Attrs = SftpATTRS |
|
198 |
||
199 |
sealed case class Dir_Entry(name: String, attrs: Attrs) |
|
200 |
{ |
|
201 |
def is_file: Boolean = attrs.isReg |
|
202 |
def is_dir: Boolean = attrs.isDir |
|
203 |
} |
|
204 |
||
64131 | 205 |
class Sftp private[SSH]( |
64134
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
206 |
session: Session, kind: String, options: Options, channel: ChannelSftp) |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
207 |
extends Channel[ChannelSftp](session, kind, options, channel) |
64131 | 208 |
{ |
64134
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
209 |
channel.connect(connect_timeout(options)) |
57581e4026fe
proper support for exec channel (see also bash.scala);
wenzelm
parents:
64133
diff
changeset
|
210 |
|
64131 | 211 |
def home: String = channel.getHome() |
212 |
||
213 |
def chmod(permissions: Int, remote_path: String) { channel.chmod(permissions, remote_path) } |
|
214 |
def mv(remote_path1: String, remote_path2: String): Unit = |
|
215 |
channel.rename(remote_path1, remote_path2) |
|
216 |
def rm(remote_path: String) { channel.rm(remote_path) } |
|
217 |
def mkdir(remote_path: String) { channel.mkdir(remote_path) } |
|
218 |
def rmdir(remote_path: String) { channel.rmdir(remote_path) } |
|
219 |
||
64132 | 220 |
def stat(remote_path: String): Dir_Entry = |
221 |
Dir_Entry(remote_path, channel.stat(remote_path)) |
|
222 |
||
223 |
def read_dir(remote_path: String): List[Dir_Entry] = |
|
224 |
{ |
|
225 |
val dir = channel.ls(remote_path) |
|
226 |
(for { |
|
227 |
i <- (0 until dir.size).iterator |
|
228 |
a = dir.get(i).asInstanceOf[AnyRef] |
|
229 |
name = Untyped.get[String](a, "filename") |
|
230 |
attrs = Untyped.get[Attrs](a, "attrs") |
|
231 |
if name != "." && name != ".." |
|
232 |
} yield Dir_Entry(name, attrs)).toList |
|
233 |
} |
|
234 |
||
235 |
def find_files(remote_path: String, pred: Dir_Entry => Boolean = _ => true): List[Dir_Entry] = |
|
236 |
{ |
|
237 |
def find(dir: String): List[Dir_Entry] = |
|
238 |
read_dir(dir).flatMap(entry => |
|
239 |
{ |
|
240 |
val file = dir + "/" + entry.name |
|
64133 | 241 |
if (entry.is_dir) find(file) |
242 |
else if (pred(entry)) List(entry.copy(name = file)) |
|
243 |
else Nil |
|
64132 | 244 |
}) |
245 |
find(remote_path) |
|
246 |
} |
|
247 |
||
64131 | 248 |
def open_input(remote_path: String): InputStream = channel.get(remote_path) |
249 |
def open_output(remote_path: String): OutputStream = channel.put(remote_path) |
|
250 |
||
251 |
def read_file(remote_path: String, local_path: Path): Unit = |
|
252 |
channel.get(remote_path, File.platform_path(local_path)) |
|
253 |
def read_bytes(remote_path: String): Bytes = |
|
254 |
using(open_input(remote_path))(Bytes.read_stream(_)) |
|
255 |
def read(remote_path: String): String = |
|
256 |
using(open_input(remote_path))(File.read_stream(_)) |
|
257 |
||
258 |
def write_file(remote_path: String, local_path: Path): Unit = |
|
259 |
channel.put(File.platform_path(local_path), remote_path) |
|
260 |
def write_bytes(remote_path: String, bytes: Bytes): Unit = |
|
261 |
using(open_output(remote_path))(bytes.write_stream(_)) |
|
262 |
def write(remote_path: String, text: String): Unit = |
|
263 |
using(open_output(remote_path))(stream => Bytes(text).write_stream(stream)) |
|
264 |
} |
|
265 |
||
64129 | 266 |
|
64123 | 267 |
/* session */ |
268 |
||
64130 | 269 |
class Session private[SSH](val session_options: Options, val session: JSch_Session) |
64123 | 270 |
{ |
271 |
override def toString: String = |
|
272 |
(if (session.getUserName == null) "" else session.getUserName + "@") + |
|
273 |
(if (session.getHost == null) "" else session.getHost) + |
|
64126 | 274 |
(if (session.getPort == 22) "" else ":" + session.getPort) + |
275 |
(if (session.isConnected) "" else " (disconnected)") |
|
64123 | 276 |
|
64126 | 277 |
def close { session.disconnect } |
64123 | 278 |
|
64135
865dda40e1cc
provide execute operation, similar to Isabelle_System.bash;
wenzelm
parents:
64134
diff
changeset
|
279 |
def execute(command: String, |
865dda40e1cc
provide execute operation, similar to Isabelle_System.bash;
wenzelm
parents:
64134
diff
changeset
|
280 |
options: Options = session_options, |
865dda40e1cc
provide execute operation, similar to Isabelle_System.bash;
wenzelm
parents:
64134
diff
changeset
|
281 |
progress_stdout: String => Unit = (_: String) => (), |
865dda40e1cc
provide execute operation, similar to Isabelle_System.bash;
wenzelm
parents:
64134
diff
changeset
|
282 |
progress_stderr: String => Unit = (_: String) => (), |
865dda40e1cc
provide execute operation, similar to Isabelle_System.bash;
wenzelm
parents:
64134
diff
changeset
|
283 |
strict: Boolean = true): Process_Result = |
865dda40e1cc
provide execute operation, similar to Isabelle_System.bash;
wenzelm
parents:
64134
diff
changeset
|
284 |
exec(command, options).result(progress_stdout, progress_stderr, strict) |
865dda40e1cc
provide execute operation, similar to Isabelle_System.bash;
wenzelm
parents:
64134
diff
changeset
|
285 |
|
64131 | 286 |
def exec(command: String, options: Options = session_options): Exec = |
64129 | 287 |
{ |
64130 | 288 |
val kind = "exec" |
289 |
val channel = session.openChannel(kind).asInstanceOf[ChannelExec] |
|
64129 | 290 |
channel.setCommand(command) |
64131 | 291 |
new Exec(this, kind, options, channel) |
64129 | 292 |
} |
64123 | 293 |
|
64131 | 294 |
def sftp(options: Options = session_options): Sftp = |
64130 | 295 |
{ |
296 |
val kind = "sftp" |
|
297 |
val channel = session.openChannel(kind).asInstanceOf[ChannelSftp] |
|
64131 | 298 |
new Sftp(this, kind, options, channel) |
64130 | 299 |
} |
64137 | 300 |
|
301 |
||
302 |
/* tmp dirs */ |
|
303 |
||
304 |
def rm_tree(remote_dir: String): Unit = |
|
305 |
execute("rm -r -f " + File.bash_string(remote_dir)).check |
|
306 |
||
307 |
def tmp_dir(): String = |
|
308 |
execute("mktemp -d -t tmp.XXXXXXXXXX").check.out |
|
309 |
||
310 |
def with_tmp_dir[A](body: String => A): A = |
|
311 |
{ |
|
312 |
val remote_dir = tmp_dir() |
|
313 |
try { body(remote_dir) } finally { rm_tree(remote_dir) } |
|
314 |
} |
|
64123 | 315 |
} |
316 |
} |
|
317 |
||
64130 | 318 |
class SSH private(val options: Options, val jsch: JSch) |
64123 | 319 |
{ |
64141 | 320 |
def open_session(host: String, port: Int = 22, user: String = ""): SSH.Session = |
64123 | 321 |
{ |
64141 | 322 |
val session = jsch.getSession(if (user == "") null else user, host, port) |
64125
a034dac5ca3c
clarified (hardwired!) default (see also jEdit/FTP);
wenzelm
parents:
64124
diff
changeset
|
323 |
|
a034dac5ca3c
clarified (hardwired!) default (see also jEdit/FTP);
wenzelm
parents:
64124
diff
changeset
|
324 |
session.setUserInfo(SSH.No_User_Info) |
a034dac5ca3c
clarified (hardwired!) default (see also jEdit/FTP);
wenzelm
parents:
64124
diff
changeset
|
325 |
session.setConfig("MaxAuthTries", "3") |
a034dac5ca3c
clarified (hardwired!) default (see also jEdit/FTP);
wenzelm
parents:
64124
diff
changeset
|
326 |
|
64130 | 327 |
if (options.bool("ssh_compression")) { |
64123 | 328 |
session.setConfig("compression.s2c", "zlib@openssh.com,zlib,none") |
329 |
session.setConfig("compression.c2s", "zlib@openssh.com,zlib,none") |
|
330 |
session.setConfig("compression_level", "9") |
|
331 |
} |
|
64125
a034dac5ca3c
clarified (hardwired!) default (see also jEdit/FTP);
wenzelm
parents:
64124
diff
changeset
|
332 |
|
64130 | 333 |
session.connect(SSH.connect_timeout(options)) |
334 |
new SSH.Session(options, session) |
|
64123 | 335 |
} |
336 |
} |