scp protocol error: bad mode

when I try a scp transfer I get this error:

protocol error: bad mode

PD: I can establish a ssh connection.


So, this is a bit of question necromancy, but since I got here, and then realised what the answer was after reading the first answer, I figured I'd put this here for other wayward souls.

Because of the way scp works (over stdin/stdout over ssh AFAIK), having a naive bashrc that prints messages breaks the formatting scp is expecting, and thus the connection.

As suggested in various answers elsewhere (linked below), modifying your dot-files is usually the way to fix this:

  • You can check in the relevant file (usually .bashrc) whether the shell is interactive before printing messages,
  • Or, slightly less directly, check whether PS1 is blank (which it should be in a noninteractive session unless something has altered it).

the problem was a personalized welcome message of bash