Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Aug 23 '11 at 1:44

This question came from our site for professional and enthusiast programmers.

2  
Is it possible that you run a command (via ssh) on the remote server? If so, you can tar the files locally and do a cat phpfiles.tar | ssh user@remote "cd destination && tar cf -" to transfer all you files in one run. –  mpy Mar 16 '13 at 17:18
    
Did you actually tried your last find command with multiple {} tokens? I looks promising (you can use multiple {}), perhaps you need to specify user@remote:~/{} as destination. –  mpy Mar 16 '13 at 17:20
    
Oups, this question was nearly two year ago... I am wondering why it showed on top of the questions rigth now... –  mpy Mar 16 '13 at 17:23
add comment

3 Answers 3

up vote 1 down vote accepted

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
share|improve this answer
add comment

Can you not do scp -r *.php destination ?

share|improve this answer
    
but will that copy all *.php files in subdirectories as well? –  cwd Aug 16 '11 at 21:15
    
@cwd: What is your exact requirement? –  hari Aug 17 '11 at 21:18
    
updated the question –  cwd Aug 18 '11 at 3:18
    
I am still not sure what you are asking here. what files you want to copy from /local/html? all *.php files? only changed *.php files? what does argument -name mean? –  hari Aug 18 '11 at 5:08
    
-name is the paramater that rsync uses to filter only php files. i would ideally like to copy only changed files (like rsync) but since rsync is not available I would like to just copy php files only (to save bandwidth). Does that make sense? I guess I could do a find -exec scp command but I would need to grab the basepath and make sure that gets added to the destination argument as well. just seems like there should be an easy way to do it. –  cwd Aug 19 '11 at 3:07
add comment

scp -r user@ip:/data/files/*.php /tmp/files/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.