scp certain files only

4

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.

cwd

Posted 2011-08-16T19:44:54.090

Reputation: 13 508

2Is 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 – 2013-03-16T17:18:29.473

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 – 2013-03-16T17:20:06.120

Oups, this question was nearly two year ago... I am wondering why it showed on top of the questions rigth now... – mpy – 2013-03-16T17:23:14.193

Answers

2

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

Florenz Kley

Posted 2011-08-16T19:44:54.090

Reputation: 1 453

0

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

hari

Posted 2011-08-16T19:44:54.090

Reputation: 545

but will that copy all *.php files in subdirectories as well? – cwd – 2011-08-16T21:15:20.063

@cwd: What is your exact requirement? – hari – 2011-08-17T21:18:58.570

updated the question – cwd – 2011-08-18T03:18:42.993

I am still not sure what you are asking here. what files you want to copy from /local/html? all .php files? only changed `.phpfiles? what does argument-name` mean? – hari – 2011-08-18T05:08:22.260

-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 – 2011-08-19T03:07:59.700

-1

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

KBastos

Posted 2011-08-16T19:44:54.090

Reputation: 11