14

I am trying to scp a file from a server to my local machine, but it is giving me this error:

protocol error: unexpected <newline>

This is my syntax:

scp user@server:/path/to/file .

It did not work on this server, but then I tried the same command on my other server, so I can only assume that it is something wrong with my server and not the syntax of the scp command.

Any ideas?

4
  • Please post your ~/.bashrc on the server.
    – quanta
    Nov 7, 2011 at 4:13
  • Thanks for the help quanta. I edited my .bashrc just before seeing your post. The issue was that I had an echo statement in it. Thanks for the help!
    – srchulo
    Nov 7, 2011 at 4:16
  • @Miles, I tried but I have to wait 8 hours because I have a reputation of less than 100. I will post it as an answer when that time is up.
    – srchulo
    Nov 7, 2011 at 4:29
  • FYI, I ran into this issue and... <sheepish>my scp command was incorrect</sheepish>. So, it could just be that. Apr 20, 2017 at 17:01

3 Answers 3

26

One of your login scripts (.bashrc/.cshrc/etc.) is outputting data to the terminal when it shouldn't be. This is causing scp to error when it is connecting and getting ready to copy as it starts receiving extra data it doesn't expect. Remove output that is generated here.

You can check if your terminal is interactive and only output text by using the following code in a bashrc. Something equivalent exists for other shells as well:

if shopt -q login_shell; then
    [any code that outputs text here]
fi
2

Found the solution. My .bashrc file and .bash_logout were set to echo out information to me whenever I log in/out. Apparently that echoed new line was giving scp some issues. I commented out my echo statements and that did the trick!

-1

I had a similar issue. The reason was exactly this: I have an "echo "some text" " command in my .bashrc for printing the status of the proxy. And this "echo "some text" " was causing scp to fail. So by removing the "echo" in the .bashrc file, I get transferred the files using scp.

1
  • 1
    This does not sound any different from the other two answers posted seven years ago.
    – kasperd
    Feb 5, 2019 at 10:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .