Linux – scp certain files only

linuxrsyncscpunix

I am trying to copy changed files to godaddy via ssh. Godaddy is terrible and so they of course do not allow rsync. I can use scp, but I really only want to copy changed files. I don't think this is possible, so I was wondering if perhaps I could scp only all php files.

There are a lot of sub directories, though, so I need to use the -r option.


Is there a way I can use scp to copy all files with extension php, recursively? like this:

scp -r -name "*php" /local/html/ user@server:/home/html/
(does not work)

DESIRED RESULT

//on local machine
$ find ./source

source/1.php
source/2.php
source/sub
source/sub/3.php
source/sub/4.php
source/sub/DONT-copy.txt
source/sub/DONT-copy.png
source/sub/sub2
source/sub/sub2/5.php
source/sub/sub2/6.php

//command to copy the files
$ [scp command here]

//on remote server
$ find ./destination

destination/1.php
destination/2.php
destination/sub
destination/sub/3.php
destination/sub/4.php
destination/sub/sub2
destination/sub/sub2/5.php
destination/sub/sub2/6.php

THIS DOES NOT WORK

//on local machine
$ find ./source

source/1.php
source/2.php
source/sub
source/sub/3.php
source/sub/4.php
source/sub/DONT-copy.txt
source/sub/DONT-copy.png
source/sub/sub2
source/sub/sub2/5.php
source/sub/sub2/6.php

//command to copy the files
$ cd source; scp -r *.php user@remote:/destination 

//on remote server
$ find ./destination

destination/1.php
destination/2.php

Perhaps we could try and use find, as well, but I'm pretty sure this will not work as is:

find ./source -name "*.php" -exec scp {} user@remote:{} \;

That won't work because I don't think you can use multiple {} operators in find.

Also, it might be tricky to get the paths to line up on the remote server, for example if find was returning /users/johndoe/documents/source/1.php and you wanted it to end up at /home/jane/www/destination/1.php on the remote server.

Best Answer

here's what I do when a host ony allows pushing stuff, and no rsync:

  • create a "shadow" directory on your local machine to resemble the target structure
  • use rsync to push to this shadow directory, and capture the output (there's --log-file if you want to script it)
  • from the rsync output, determine the files you need to delete, or push and make a list
  • maybe (depends on the way you push): create a package from the files that need to be changed only
  • start your push tool - ftp, scp, whatever - and let it run on the files from the list
Related Question