eudoxia0/trivial-ssh

Can't upload files

Closed this issue · 2 comments

I can run remote commands with trivial-ssh, but any attempt to upload a file results errors like this...

The value 115 is not of type CHARACTER.
[Condition of type TYPE-ERROR]

Restarts:
0: [RETRY] Retry SLIME interactive evaluation request.
1: [*ABORT] Return to SLIME's top level.
2: [ABORT] abort thread (#<THREAD "worker" RUNNING {1007C043E3}>)

Backtrace:
0: ((SB-IMPL::OPTIMIZED-DATA-VECTOR-SET CHARACTER) # # #)
1: (SB-IMPL::ANSI-STREAM-READ-SEQUENCE "^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@..
2: (READ-SEQUENCE "^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@..
3: (UIOP/STREAM:COPY-STREAM-TO-STREAM #<SB-SYS:FD-STREAM for "file /tmp/foo" {1009BFF9B3}> #<LIBSSH2:SSH-CHANNEL-SEND {1009C09F23}> :ELEMENT-TYPE NIL :BUFFER-SIZE NIL :LINEWISE NIL :PREFIX NIL)
4: (TRIVIAL-SSH:UPLOAD-FILE #<LIBSSH2:SSH-CONNECTION {1009BFE3D3}> "/tmp/foo" "/tmp/analysis-copy2")
5: ((LAMBDA ()))
6: (SB-INT:SIMPLE-EVAL-IN-LEXENV (TRIVIAL-SSH:WITH-CONNECTION (CONN "localhost" (TRIVIAL-SSH:PASS "green" "PASSWORD")) (TRIVIAL-SSH:UPLOAD-FILE CONN "/tmp/foo" "/tmp/analysis-copy2")) #)
7: (EVAL (TRIVIAL-SSH:WITH-CONNECTION (CONN "localhost" (TRIVIAL-SSH:PASS "green" "PASSWORD")) (TRIVIAL-SSH:UPLOAD-FILE CONN "/tmp/foo" "/tmp/analysis-copy2")))
8: ((LAMBDA NIL :IN SWANK:INTERACTIVE-EVAL))

I was able to fix this by copying with :element-type '(unsigned-byte 8). Thanks to @fare for figuring this out.

(defun my-upload-file (conn local remote)
   (with-open-file (file-stream (namestring local)
                               :direction :input
                               :element-type '(unsigned-byte 8))
    (libssh2:with-scp-output (upload-stream conn
                                            (namestring remote)
                                            (file-length file-stream))
      (uiop:copy-stream-to-stream file-stream upload-stream :element-type '(unsigned-byte 8)))))

This was fixed by #11