File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,21 @@ Note that any sftp commands that change the state of the sftp session (such as
52
52
cd) do not work with the simplified interface, as a new session is created each
53
53
time.
54
54
55
+ SSH tunneling is also supported:
56
+
57
+ (with-ssh-agent []
58
+ (let [session (session "localhost" :strict-host-key-checking :no)]
59
+ (with-local-tunnel session 8080 80
60
+ (with-connection session
61
+ (while (connected? session)
62
+ (Thread/sleep 100))))))
63
+
64
+ or more conveniently:
65
+
66
+ (with-ssh-agent []
67
+ (let [session (session "localhost" :strict-host-key-checking :no)]
68
+ (ssh-tunnel session 8080 80)))
69
+
55
70
## Documentation
56
71
57
72
[ Annotated source] ( http:/hugoduncan.github.com/clj-ssh/uberdoc.html ) .
Original file line number Diff line number Diff line change @@ -392,6 +392,25 @@ 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]
398
+ `(try
399
+ (.setPortForwardingL ~session ~local-port " localhost" ~remote-port)
400
+ ~@body
401
+ (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 )))))
413
+
395
414
(defn default-session [host username port password]
396
415
(doto (session-impl
397
416
(or (and (bound? #'*ssh-agent*) *ssh-agent*) (create-ssh-agent ))
You can’t perform that action at this time.
0 commit comments