derekhed
04-14-2006, 04:19 PM
I have a directory of hundreds of arbitrarily-named graphic files. From time to time I want to upload a subset of these to my server, usually ones I have worked on recently. How can I send just a subset of these files to a scp command? Does scp have a flag like ftp's -i where a file of commands can be read? Is there a neat trick with grep or find that can pipe the files I want moved to scp?
I have been using the GUI tool Transmit quite successfully, but every now and then I'd like to remain in the CLI.
Thanks in advance.
dmacks
04-14-2006, 04:55 PM
The command 'cat' didplays the contents of a file. Sounds like you want to scp "the output of cat" instead of an explicit filename?scp `cat filelist.txt` somewhere.com:
derekhed
04-14-2006, 05:06 PM
Great! That worked beautifully.
I used this to get my list:find . -newer oldest_unwanted_file.jpg -name '*.jpg' -print >filelist.txt where oldest_unwanted_file is the last image I DON'T want. Then your codescp `cat filelist.txt` myAccount@server.ofhappiness.com:~/path/to/images/Thanks! :)
Gnarlodious
04-14-2006, 05:07 PM
You can transfer a set of files with one cammand:
scp -2 username@gnarlodious.com:/var/log/httpd/\{gnarlodious,spectrumology\}_access_log.* /private/tmp
That command moves Apache logfiles from a Server X machine to my computer. scp operates full regular expressions in the name, or you can list them the lang way.
I have written an Applescript droplet to upload files to servers if you're interested in that.
derekhed
04-14-2006, 05:14 PM
My files are named randomly (seemed like a good idea at the time) like this:
805095573.jpg
805095573_tn.jpg
849759938.jpg
849759938_lrg.jpg
849759938_tn.jpg
915326976.jpg
915326976_lrg.jpg
915326976_tn.jpg
920122440.jpg
920122440_lrg.jpg
920122440_tn.jpg
So I pretty much need to bust out find and learn to use it better. In this case, the -newer did the trick nicely.
Basically I am doing work on a local development box and uploading the new files. My wish list includes being able to run recursively through a directory and upload only the files I worked on that day. That would be awesome! It would have to remember the full paths I guess... :confused:
ppatoray
04-14-2006, 05:54 PM
I'm surprised that nobody has mentioned rsync. I use rsync to compare files locally and my my server, and upload/download all changed files in one shot.
Upload all changed files in a particular folder to my server:
rsync -e ssh --recursive --progress --verbose --compress --dry-run /www/htdocs/U/USERNAME/ USER@HOST:/www/htdocs/U/USERNAME
the --dry-run does exactly that, you'll see which files have been changed and would be uploaded. Once you're sure that you've got the right files, simply remove the --dry-run from the command.
To flip it around and download all changed files from your server, flip the order in the command:
rsync -e ssh --recursive --progress --verbose --compress --dry-run USER@HOST:/www/htdocs/U/USERNAME/ /www/htdocs/U/USERNAME
man rsync or google for it to find more examples.
derekhed
04-14-2006, 05:56 PM
Sounds like it could be a useful work around for the 'only upload recently modified files' problem. What about filtering out all those pesky .svn directories I don't want uploaded? Is it simple to create filters on file names or types?
I almost have the `cat filename` solution working except that scp puts all the files in one place and doesn't move them into the proper subdirectories on the server. :-(
derekhed
04-14-2006, 06:04 PM
This is the response when trying to use the rsync command:
building file list ...
1136 files to consider
created directory /Library/WebServer/WebSites/accountname/site.org/approot/
push_dir /Library/WebServer/WebSites/accountname/site.org/approot/ : No such file or directory (2)
rsync error: errors selecting input/output files, dirs (code 3) at /SourceCache/rsync/rsync-8/rsync/main.c(292)
rsync: connection unexpectedly closed (8 bytes read so far)
rsync error: error in rsync protocol data stream (code 12) at io.c(189)
Odd... I have no idea what this is about. I don't mind using the find technique if I could figure out how to target the destination server's subdirectories.
ppatoray
04-14-2006, 06:05 PM
Just use the --exclude switch in rsync. Add --exclude=.svn and that should take care of it. You can also use wildcards here, like --exclude=sess_* or --exclude=*.psd
So your upload command would look like:
rsync -e ssh --recursive --progress --verbose --compress --dry-run --exclude=.svn /www/htdocs/U/USERNAME/ USER@HOST:/www/htdocs/U/USERNAME
ppatoray
04-14-2006, 06:08 PM
Please include the full command that you used, not just the output. I've never seen these type of errors when using rsync.
derekhed
04-14-2006, 06:11 PM
I PMed you the full command and result. I have write access to the target directory, and the folders already exist. I guess it could be something to do with my host's setup. I don't control it.
rsync version 2.6.0 protocol version 27
ppatoray
04-14-2006, 06:38 PM
I PMed you back. It looks like you didn't change the path on the destination server, and you were trying to dump the files into a directory that doesn't exist on the remote server (/Library/WebServer/WebSites/accountname/site.org/approot/). Change this to your path to your htdocs folder on your server (/var/www/html/accountname/site.org/approot/ or similar). Let me know if you have any more problems.
derekhed
04-14-2006, 06:43 PM
My host is a Mac-based company. They do an awesome job, and thus the web server paths are not the standard *nix type but the more familiar mac ones.
Here is the obfuscated command:
$ rsync -e ssh --recursive --progress --verbose --compress --dry-run --exclude=.svn /Users/derekhed/Sites/Aikido_Fuse/trunk/approot/ accnt@cheops.serverlogistics.com:/Library/WebServer/WebSites/accnt/site_name/approot
Password:
building file list ...
254 files to consider
created directory /Library/WebServer/WebSites/accnt/site_name/approot
push_dir /Library/WebServer/WebSites/accnt/site_name/approot : No such file or directory (2)
rsync error: errors selecting input/output files, dirs (code 3) at /SourceCache/rsync/rsync-8/rsync/main.c(292)
rsync: connection unexpectedly closed (8 bytes read so far)
rsync error: error in rsync protocol data stream (code 12) at io.c(189)