Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I want to send something via scp to server:

$ scp file server:
                   _____  _____  _____

, then three lines are printed and file is not copied. However I can connect to server via ssh without problem:

$ ssh server

How to make scp work?

share|improve this question
Provide more information such as the operating system, ssh config file, etc. – qroberts Feb 29 '12 at 16:11
And what are these three lines that are printed? – jjlin Feb 29 '12 at 17:05
In the normal case, when you run scp file server: (assuming "server" is a valid hostname), the file is copied to your account directory. – dan_linder Mar 1 '12 at 19:53
Can you provide the output when you run "scp -v file server:". – dan_linder Mar 1 '12 at 19:54
up vote 25 down vote accepted

One possible cause of this type of behavior is having any message print out during the login process on server. Scp depends on ssh to provide a totally transparent encrypted tunnel between the client and the server.

Check all of the login scripts on the server, and also try using a different user. Another method of identifying the source of the error is to use the -v in the command, to trace the progress of the transaction, and see where it fails. You can use up to -vvv to increase the verbosity, if necessary. Checking the various forms of scp can also be instructive, as listed in the post by InChargeOfIT.

scp, under the hood, sets up a tunnel using ssh, and then transfers the file over that tunnel, with a ssh command on the far end to catch the file as it comes over. This is illustrated by the use of tar and ssh to copy a directory structure preserving ownership and creation times with the following commands:

  tar czf - ./* | ssh tar xzf - -C ~/saved_tree

to send it over, and

ssh "tar czf - ~/saved_tree" | tar xzvf - -C ./

to get it back.

share|improve this answer
Thank you! i was scratching my head last night!!!! :) – jtanmay May 3 '13 at 13:35
It's really helpful – maple Apr 21 at 4:05

Check the target user's .bashrc or equivalent file. ~/.bashrc is sourced for non-interactive logins. If there's an echo or command that outputs anything, it will break the SCP protocol.

share|improve this answer
EUREKA! This was my problem because I had a fortune | cowsay on each login in my remote .bashrc. Now working perfectly. – Thomas Browne May 12 '15 at 10:34
You Sir, are a lifesaver. :) – Gaurav Manchanda May 13 at 18:37
If you still want your fortune | cowsay, just put it in .bash_profile. That's for interactive only logins and should not be sourced during the SCP session. – spoulson May 15 at 9:05

Edit: Are you positive you are entering in a valid path in the scp command? For example:

scp test.txt

will fail (in fact, it will just print out the command like you are seeing). In this case, you will need to provide a valid path to the remote server.. e.g., scp test.txt

Example usages:

Send a file:

scp /path/to/local/file

Get a file:

scp /path/to/local/directory


Send a file from my Desktop to my home folder on a remote server:

scp ~/Desktop/myfile.txt john_doe@

Remember the ~ is a shortcut for your home directory... e.g., /home/

Send a file to the the webroot:

scp ~/Documents/working/index.html

In this example, the user john_doe would need write privileges on the remote /var/www directory.

share|improve this answer
you are not answering the question. the commandline given by OP looks fairly ok, the interesting part are the ------ ... none of your examples relates to that. – akira Feb 29 '12 at 18:14
@akira maybe, maybe not. Not providing valid paths will cause the scp command to fail.. e.g, scp somefile Also, not having the correct permissions on the remote directory would also cause problems. Edited my answer to make it a little clearer – InChargeOfIT Feb 29 '12 at 18:17
none of your examples cover "file does not exist", none of your examples cover "permissions wrong on server side"... – akira Feb 29 '12 at 18:29
Excellent info, thank you – tjb Sep 23 '13 at 11:03

just in case you are including other scp parameters be sure to place these before the source and targets. eg this works:

scp -i ~/.ssh/some_other_key ./mysource

but this doesn't:

scp  ./mysource -i ~/.ssh/some_other_key`
share|improve this answer

You must log in to answer this question.

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