13

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?

srchulo
  • 306
  • 1
  • 2
  • 10
  • Please post your `~/.bashrc` on the server. – quanta Nov 07 '11 at 04: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 07 '11 at 04: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 07 '11 at 04:29
  • FYI, I ran into this issue and... my scp command was incorrect. So, it could just be that. – ognockocaten Apr 20 '17 at 17:01

3 Answers3

25

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
Andrew Case
  • 3,489
  • 3
  • 23
  • 39
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!

srchulo
  • 306
  • 1
  • 2
  • 10
-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.