       (reset! ssh-agent agent)))
   @ssh-agent)
 
+(def session-invalidator (atom nil))
+(defn- reset-session-invalidate
+  "This function acts as a hit on the session being active, every time this function is called
+  session invalidation is reset, when the reset invalidation expires the ssh session is
+  invalidated and set to nil"
+  []
+  (when-not (nil? @session-invalidator)
+    (future-cancel @session-invalidator))
+  (reset! session-invalidator
+          (future
+            (Thread/sleep 120000)
+            (info "Invalidating session")
+            (let [s @ssh-session]
+              (reset! ssh-session nil)
+              (reset! session-invalidator nil)
+              (ssh/disconnect s)))))
+
 (defn- session []
   "Get the currently active session, if one doesn't exist, create a new one and make sure the
   session is connected"

(ns dakait.files
  (:use compojure.core
        dakait.config
        [dakait.util :only (join-path)]
        [clojure.tools.logging :only (info error)])
  (:require 

                          :type (file-type e)
                          :size (file-size e)}))))))

(defn list-remote-files
  "Get the list of all files at the given path"
  [path]
  (let [this-channel (ssh/ssh-sftp (session))]
    (ssh/with-channel-connection this-channel
      (when-not (nil? path)
        (ssh/sftp this-channel {} :cd path))
      (ssh/sftp this-channel {} :ls))))

