How to copy only new files using "scp" command?
You can use rsync
for it. rsync
is really designed for this type of operation.
Syntax:
rsync -avh /source/path/ host:/destination/path
or
rsync -a --ignore-existing /local/directory/ host:/remote/directory/
When you run it first time it will copy all content then it will copy only new files.
If you need to tunnel the traffic through a SSH connection (for example, for confidentiality purposes), as indicated by you originally asking for a SCP-based solution, simply add -e ssh
to the parameters to rsync
. For example:
rsync -avh -e ssh /source/path/ host:/destination/path
If you want to stick with scp for any reason, you might remove w permissions on your local data (if you have the right to do it) and scp won't touch it. To be more precise:
chmod a-w local/*.tar.gz
(in your local dir)scp remote/*.tar.gz local
This is not very efficient, nice but might help if you need a fast temporary solution without changing to something else than scp. (Kudos: scp without replacing existing files in the destination )
There was no exact answer on how to do this with SCP, since that was what the original question was asking.
sudo find /files/ -type f -exec chmod a-w {} \;
scp -r [email protected]:/file/location/* /files
When it's done copying the files change the permissions back:
sudo chmod a+w -R /files