@@ -392,24 +392,28 @@ keys. All other option key pairs will be passed as SSH config options."
392
392
(.toByteArray err-stream)
393
393
(.toString err-stream out))]))))
394
394
395
- (defmacro with-local-tunnel
396
- " Creates a context in which a local SSH tunnel is established for the session. (Use before the connection is opened.)"
397
- [session local-port remote-port & body]
395
+ (defn forward-local-port
396
+ " Start local port forwarding"
397
+ ([session local-port remote-port remote-host]
398
+ (.setPortForwardingL session local-port remote-host remote-port))
399
+ ([session local-port remote-port]
400
+ (forward-local-port session local-port remote-port " localhost" )))
401
+
402
+ (defn unforward-local-port
403
+ " Remove local port forwarding"
404
+ [session local-port]
405
+ (.delPortForwardingL session local-port))
406
+
407
+ (defmacro with-local-port-forward
408
+ " Creates a context in which a local SSH tunnel is established for the session.
409
+ (Use before the connection is opened.)"
410
+ [[session local-port remote-port & [remote-host & _]] & body]
398
411
`(try
399
- (.setPortForwardingL ~session ~local-port " localhost" ~remote-port)
412
+ (forward-local-port
413
+ ~session ~local-port ~remote-port ~(or remote-host " localhost" ))
400
414
~@body
401
415
(finally
402
- (.delPortForwardingL ~session " localhost" ~local-port))))
403
-
404
- (defn ssh-tunnel
405
- " Run a ssh tunnel."
406
- [session local-port remote-port]
407
- (with-local-tunnel session local-port remote-port
408
- (.setDaemonThread session true )
409
- (with-connection session
410
- (.setServerAliveInterval session 1000 )
411
- (while (connected? session)
412
- (Thread/sleep 100 )))))
416
+ (unforward-local-port ~session ~local-port))))
413
417
414
418
(defn default-session [host username port password]
415
419
(doto (session-impl
0 commit comments