How can I get the scp command to overwrite the destination folder

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


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:

http://troy.jdmz.net/rsync/index.html https://calomel.org/rsync_tips.html

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.


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.