@@ -686,16 +686,15 @@ config options."
686
686
{:channel exec
687
687
:out-stream out-inputstream
688
688
:err-stream err-inputstream}
689
- (with-channel-connection exec
690
- (while (connected-channel? exec)
691
- (Thread/sleep 100 ))
692
- {:exit (.getExitStatus exec)
693
- :out (if (= :bytes out)
694
- (.toByteArray ^ByteArrayOutputStream out-stream)
695
- (.toString out-stream))
696
- :err (if (= :bytes out)
697
- (.toByteArray ^ByteArrayOutputStream err-stream)
698
- (.toString err-stream))}))))
689
+ (do (while (connected-channel? exec)
690
+ (Thread/sleep 100 ))
691
+ {:exit (.getExitStatus exec)
692
+ :out (if (= :bytes out)
693
+ (.toByteArray ^ByteArrayOutputStream out-stream)
694
+ (.toString out-stream))
695
+ :err (if (= :bytes out)
696
+ (.toByteArray ^ByteArrayOutputStream err-stream)
697
+ (.toString err-stream))}))))
699
698
700
699
(defn ssh
701
700
" Execute commands over ssh.
@@ -856,7 +855,7 @@ cmd specifies a command to exec. Valid commands are:
856
855
(defn- scp-send-command
857
856
" Send command to the specified output stream"
858
857
[^OutputStream out ^InputStream in ^String cmd-string]
859
- (.write out (.getBytes cmd-string))
858
+ (.write out (.getBytes ( str cmd-string " \n " ) ))
860
859
(.flush out)
861
860
(logging/tracef " Sent command %s" cmd-string)
862
861
(scp-receive-ack in)
@@ -882,38 +881,34 @@ cmd specifies a command to exec. Valid commands are:
882
881
883
882
(defn- scp-copy-file
884
883
" Send acknowledgement to the specified output stream"
885
- [send recv ^File file {:keys [mode buffer-size preserve]
884
+ [^OutputStream send ^InputStream recv ^File file {:keys [mode buffer-size preserve]
886
885
:or {mode 0644 buffer-size 1492 preserve false }}]
887
- ( logging/tracef " Sending %s " ( .getAbsolutePath file))
886
+
888
887
(when preserve
889
888
(scp-send-command
890
889
send recv
891
- (format " P %d 0 %d 0\n " (.lastModified file) (.lastModified file))))
890
+ (format " P%d 0 %d 0" (.lastModified file) (.lastModified file))))
892
891
(scp-send-command
893
892
send recv
894
- (format " C%04o %d %s\n " mode (.length file) (.getName file)))
895
- (with-open [fs ( FileInputStream. file)]
896
- (io/copy fs send :buffer-size buffer-size) )
893
+ (format " C%04o %d %s" mode (.length file) (.getName file)))
894
+ (logging/tracef " Sending %s " ( .getAbsolutePath file))
895
+ (io/copy file send :buffer-size buffer-size)
897
896
(scp-send-ack send)
898
- (logging/trace " Sent ACK after send" )
899
- (scp-receive-ack recv)
900
- (logging/trace " Received ACK after send" ))
897
+ (logging/trace " Receiving ACK after send" )
898
+ (scp-receive-ack recv))
901
899
902
900
(defn- scp-copy-dir
903
901
" Send acknowledgement to the specified output stream"
904
902
[send recv ^File dir {:keys [dir-mode] :or {dir-mode 0755 } :as options}]
905
- (logging/trace " Sending directory %s" (.getAbsolutePath dir))
903
+ (logging/tracef " Sending directory %s" (.getAbsolutePath dir))
906
904
(scp-send-command
907
905
send recv
908
906
(format " D%04o 0 %s" dir-mode (.getName dir)))
909
907
(doseq [^File file (.listFiles dir)]
910
908
(cond
911
909
(.isFile file) (scp-copy-file send recv file options)
912
910
(.isDirectory file) (scp-copy-dir send recv file options)))
913
- (scp-send-ack send)
914
- (logging/trace " Sent ACK after send" )
915
- (scp-receive-ack recv)
916
- (logging/trace " Received ACK after send" ))
911
+ (scp-send-command send recv " E" ))
917
912
918
913
(defn- scp-files
919
914
[paths recursive]
@@ -1025,7 +1020,7 @@ cmd specifies a command to exec. Valid commands are:
1025
1020
(connect session))
1026
1021
(let [[^PipedInputStream in
1027
1022
^PipedOutputStream send] (streams-for-in )
1028
- cmd (format " scp %s -t %s" (:remote-flags opts " " ) remote-path)
1023
+ cmd (format " scp %s %s -t %s" (:remote-flags opts " " ) ( if recursive " -r " " " ) remote-path)
1029
1024
_ (logging/tracef " scp-to: %s" cmd)
1030
1025
{:keys [^ChannelExec channel ^PipedInputStream out-stream]}
1031
1026
(ssh-exec session cmd in :stream opts)
@@ -1084,8 +1079,9 @@ cmd specifies a command to exec. Valid commands are:
1084
1079
(->>
1085
1080
(select-keys opts [:recursive :preserve ])
1086
1081
(filter val)
1087
- (map (fn [k v] ( k flags) )))))
1082
+ (map (comp flags key )))))
1088
1083
(string/join " " remote-paths))
1084
+ _ (println cmd)
1089
1085
_ (logging/tracef " scp-from: %s" cmd)
1090
1086
{:keys [^ChannelExec channel
1091
1087
^PipedInputStream out-stream]}
0 commit comments