File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -399,6 +399,29 @@ keys. All other option key pairs will be passed as SSH config options."
399
399
(.toByteArray err-stream)
400
400
(.toString err-stream out))]))))
401
401
402
+ (defn forward-remote-port
403
+ " Start remote port forwarding"
404
+ ([session remote-port local-port local-host]
405
+ (.setPortForwardingR session remote-port local-host local-port))
406
+ ([session remote-port local-port]
407
+ (forward-remote-port session local-port remote-port " localhost" )))
408
+
409
+ (defn unforward-remote-port
410
+ " Remove remote port forwarding"
411
+ [session remote-port]
412
+ (.delPortForwardingR session remote-port))
413
+
414
+ (defmacro with-remote-port-forward
415
+ " Creates a context in which a remote SSH tunnel is established for the session.
416
+ (Use before the connection is opened.)"
417
+ [[session remote-port local-port & [local-host & _]] & body]
418
+ `(try
419
+ (forward-remote-port
420
+ ~session ~remote-port ~local-port ~(or local-host " localhost" ))
421
+ ~@body
422
+ (finally
423
+ (unforward-remote-port ~session ~remote-port))))
424
+
402
425
(defn forward-local-port
403
426
" Start local port forwarding"
404
427
([session local-port remote-port remote-host]
You can’t perform that action at this time.
0 commit comments