Scp prints some weird characters and doesn’t copy files

scp

I'm trying to copy a small file from another computer in the network using scp, the computer is running Linux Mint 18.3.

I tried from macOS and I get this:

$ scp fyde@192.168.1.211:/home/fyde/Downloads/notes/ubuntu.txt .                          
fyde@192.168.1.211's password:
\033]4;0;#2b1229\033\\033]4;1;#FFD36D\033\\033]4;2;#6559B6\033\\033]4;3;#E1549E\033\\033]4;4;#788FA3\033\\033]4;5;#778BE1\033\\033]4;6;#D88AA7\033\\033]4;7;#d2d8d2\033\\033]4;8;#939793\033\\033]4;9;#FFD36D\033\\033]4;10;#6559B6\033\\033]4;11;#E1549E\033\\033]4;12;#788FA3\033\\033]4;13;#778BE1\033\\033]4;14;#D88AA7\033\\033]4;15;#d2d8d2\033\\033]10;#d2d8d2\033\\033]11;#2b1229\033\\033]12;#FFD36D\033\\033]13;#d2d8d2\033\\033[s\033[1000H\033[8m\033]708;#2b1229\033\\033[u\033]13;#d2d8d2\033\C0644 6743 ubuntu.txt

I tried from an Ubuntu machine and I get a similar thing:

$ scp fyde@192.168.1.211:/home/fyde/Downloads/notes/ubuntu.txt .
fyde@192.168.1.211's password:
C0644 6743 ubuntu.txt

I tried with different files and I get the same result, copying from other computers works fine.

Anyone knows what's happening?

Best Answer

You've botched your login shell's startup scripts, and that is bamboozling scp.

scp is starting a non-interactive SSH session and invoking a non-interactive login shell without a controlling terminal. But your shell's startup scripts are not checking for this case properly, and are doing the things that they do for interactive shells invoked with a controlling terminal. Indeed, those shells are blithely and incorrectly assuming that the terminal is a particular type of terminal.

All of that mysterious output is the result of commands in your shell's startup scripts outputting various OSC control sequences (␛[ and ␛/ being the ECMA-48 7-bit aliases for the OSC and ST control characters) and CSI control sequenes (␛] being the ECMA-48 7-bit alias for the CSI control character). These sequences are attempting to change colour mappings and affect terminal scrollback. They only work with a specific terminal emulator.

But the local end of your SSH connection is not something that mirrors all of this onto your local terminal (which, given that you are using MacOS, is unlikely to be that specific terminal emulator and more likely to be something like iTerm2, in any event). It is the local scp program, which is expecting to talk a specialized protocol over the SSH connection, that implements the file copying mechanism. All of the junk that your shell's startup scripts are erroneously spitting out even in non-interactive mode, is jumbling its communications.

Correct your faulty shell startup scripts to not attempt to do terminal stuff when they are invoked non-interactively or without a controlling terminal.

Further reading

Related Question