3

I am trying to copy files from a folder on a server using a batch file, however, I don't want the files in the destination folder to be overwritten. This is what I have:

set /p address=ip address:
pause
pscp -pw "password" "username"@%address%:/folder path/* c:\folderpath

This works, however, when it runs it overwrites the files in the destination folder. Is there a way to make it skip over the files that are already in the destination folder?

Worthwelle
  • 4,538
  • 11
  • 21
  • 32
jhast1
  • 31
  • 1
  • 1
  • 2
  • 1
    See also: http://superuser.com/questions/131801/can-i-make-scp-ask-before-overwriting-an-existing-file, http://aplawrence.com/Basics/no_clobber_scp.html, http://www.linuxquestions.org/questions/linux-software-2/scp-recurse-but-not-overwrite-56005/ - the general suggestion seems to be 'use rsync instead'. Another suggestion is to use scp to transfer to a temporary directory and use a server-side script to copy things without overwriting. I imagine it would also be possible to use ssh to check for the existence of files in a client-side script, but that sounds a little tedious. – Bob Apr 13 '13 at 07:31
  • See also: http://stackoverflow.com/questions/13410990/prevent-overwriting-of-files-when-using-scp - yea, another rsync suggestion. – Bob Apr 13 '13 at 07:36

2 Answers2

2

The SCP protocol isn't very sophisticated. The sending side can only blindly send the files and directories to the receiver. There's no standard option to avoid overwriting files on the destination.

You should look at more sophisticated transfer protocols, like SFTP or rsync as in the comments.

Kenster
  • 7,483
  • 2
  • 32
  • 44
1

TL;DR answer from those comments:

rsync -e ssh --ignore-existing server.xxx.com:/path/\* /destination/path

Better yet, if the server also supports CIFS ("network shares"), use that with cp -u.

Camille Goudeseune
  • 2,297
  • 4
  • 32
  • 41