Skip to content

Commit 6d5bba9

Browse files
committed
Merge pull request #34 from moonpolysoft/working-recursive-scp
Fixed recursive scp invocation.
2 parents 071f66f + bbbc473 commit 6d5bba9

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/clj_ssh/ssh.clj

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ cmd specifies a command to exec. Valid commands are:
856856
(defn- scp-send-command
857857
"Send command to the specified output stream"
858858
[^OutputStream out ^InputStream in ^String cmd-string]
859-
(.write out (.getBytes cmd-string))
859+
(.write out (.getBytes (str cmd-string "\n")))
860860
(.flush out)
861861
(logging/tracef "Sent command %s" cmd-string)
862862
(scp-receive-ack in)
@@ -882,22 +882,21 @@ cmd specifies a command to exec. Valid commands are:
882882

883883
(defn- scp-copy-file
884884
"Send acknowledgement to the specified output stream"
885-
[send recv ^File file {:keys [mode buffer-size preserve]
885+
[^OutputStream send ^InputStream recv ^File file {:keys [mode buffer-size preserve]
886886
:or {mode 0644 buffer-size 1492 preserve false}}]
887-
(logging/tracef "Sending %s" (.getAbsolutePath file))
887+
888888
(when preserve
889889
(scp-send-command
890890
send recv
891-
(format "P %d 0 %d 0\n" (.lastModified file) (.lastModified file))))
891+
(format "P%d 0 %d 0" (.lastModified file) (.lastModified file))))
892892
(scp-send-command
893893
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))
894+
(format "C%04o %d %s" mode (.length file) (.getName file)))
895+
(logging/tracef "Sending %s" (.getAbsolutePath file))
896+
(io/copy file send :buffer-size buffer-size)
897897
(scp-send-ack send)
898-
(logging/trace "Sent ACK after send")
899-
(scp-receive-ack recv)
900-
(logging/trace "Received ACK after send"))
898+
(logging/trace "Receiving ACK after send")
899+
(scp-receive-ack recv))
901900

902901
(defn- scp-copy-dir
903902
"Send acknowledgement to the specified output stream"
@@ -910,10 +909,7 @@ cmd specifies a command to exec. Valid commands are:
910909
(cond
911910
(.isFile file) (scp-copy-file send recv file options)
912911
(.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"))
912+
(scp-send-command send recv "E"))
917913

918914
(defn- scp-files
919915
[paths recursive]
@@ -1025,7 +1021,7 @@ cmd specifies a command to exec. Valid commands are:
10251021
(connect session))
10261022
(let [[^PipedInputStream in
10271023
^PipedOutputStream send] (streams-for-in)
1028-
cmd (format "scp %s -t %s" (:remote-flags opts "") remote-path)
1024+
cmd (format "scp %s %s -t %s" (:remote-flags opts "") (if recursive "-r" "") remote-path)
10291025
_ (logging/tracef "scp-to: %s" cmd)
10301026
{:keys [^ChannelExec channel ^PipedInputStream out-stream]}
10311027
(ssh-exec session cmd in :stream opts)

0 commit comments

Comments
 (0)