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

I am using the scp command to copy some files to a remote pc, as you do with scp :)

I note that the default behaviour of an scp copy for files is to overwrite any existing files. Now I want to copy a folder so I do basically the same thing:

scp -r <source_path> user@myOtherPc:<dest_path>

Where the parts in <> are my folder paths. However when I run this I get the message "file exists". Is there a way around this? some sort of force over-write?

Thanks, Fodder

share|improve this question
Could you give some examples of path ? I do not perform to reproduce this on my system. Also, have you checked file permissions ? – Levans Sep 23 '13 at 15:51
Does it give you any useful info if you use verbose mode? -v. Also, are you using absolute or relative path on the destination side? I think if the destination folder already exists, it is going to create the source path inside the destination folder rather than overwrite (testdir/testdir) – beroe Sep 24 '13 at 1:47
It is strange that you get this. Supposedly scp doesn't have noclobber... – beroe Sep 24 '13 at 1:57
@Levans I did not check the permissions, I have just taken a look and I think you may be right. I deleted everything in the target area and started again using only the "scp" command and using "root" user and I was able to copy the files/folder multiple times :) ... I am not 100% sure what permission issue I had, but now I have a "handle" on the issue I can probably figure it, thanks – code_fodder Sep 24 '13 at 6:38
@beroe Yes, this is what I thought too... it did confuse me, but I think I have made some sort of user error here with the permissions, I am not linux expert yet :( But I will try the verbose-ness next time I have an issue like that to get more info, thanks. Also I have noticed that sometimes you get the "folder-inside-the folder" happening... but that is another issue :o – code_fodder Sep 24 '13 at 6:41

Like Levans, I have been unable to replicate this, but have you considered using rsync over ssh instead? If you're copying large numbers of files, rsync may be a better option than scp. There are a number of good guides to it online, such as these:

That first link deals with automated backups via cron, so some of the instructions (like creating an ssh key without a passphrase) may not be relevant to you.

share|improve this answer
Interesting, I did not know you can use rsync over in that way... just had a quick look at the man page and looks like you can use it in a very similar way to scp with <source_path> and <user@host:dest_path> parameters. I am not 100% sure that is what I want since I want to always copy/overwrite without caring the status of what is in the dest, but still a nice idea :) – code_fodder Sep 24 '13 at 6:45
Yeah, it might be worth having a play because it should copy over the file if it has been changed (or the part of the file that has been changed, I'd need to double-check and I'm a little too tired right now). – Ben Sep 24 '13 at 12:11
haha.... don't worry about checking it, I can do that stuff... but thanks for the info :) – code_fodder Sep 24 '13 at 12:35
Ah, cool, I can stop looking at matchsticks as a means to prop my eyelids open. ;) – Ben Sep 24 '13 at 12:45

As said before, scp happily overwrites any file that is already present.

The "file exists" issue can only occur when you have some other process (like a concurrent scp process, or something else) writing folders and files to the same destination. Consider using rsync instead.

share|improve this answer

You will receive this error message if the destination directory already contains a file with the same name as the source directory you are attempting to transfer. You can not have a file with the same name as a directory in the same directory.

share|improve this answer

You must log in to answer this question.

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