I'm trying to understand how scp
works "under the hood".
The only reference I found that seem to explain how things work is a blog post on the Oracle website, through web archive.
Well, there, we can find a few examples, for instance:
{ echo D0755 0 testdir; echo C0644 6 test 123;
printf "hello\\n"; echo E; } | scp -rqt /tmp
While it does create /tmp/testdir/test 123
with the right content, it actually exit 1
. We can get more info by removing the -q
flag:
$ { echo D0755 0 testdir; echo C0644 6 test 123;
printf "hello\\n"; echo E; } | scp -tr /tmp
test 123 0% 0 0.0KB/s --:-- ETA
$ echo $?
1
So, we can see, it exits 0 and the progress is never updated.
My question is: why?
At first I thought it was because the terminal is not a SSH session, but then I actually tried to do it using golang.org/x/crypto/ssh
, and I get the same results.
My guess is that both the terminal and my implementation are missing something, I don't know what it is, though.
Any pointers?
OK, I figured it out!
Need to send a null byte after the file:
$ {
echo D0755 0 testdir;
echo C0644 6 test 123;
printf "hello\\n";
printf "\x00";
echo E;
} | scp -tr /tmp
test 123 100% 6 102.4KB/s 00:00
$ echo $?
0