#!/bin/csh -f # # Generate ftp commands to bulk-upload pictures to AtPic.com. # Group files into 100MB batches. (FTP says "102400 Kb".) # # Arguments: files to upload or directories to search for files # # This tool is meant for people who already have some basic comfort # with poking into Unix/Linix shell scripts. You may need to change # the path to find, awk, and ftp. (/usr/bin/ works for MacOS X.) # # My account ("u3160") is hard coded in the script (twice). # You will need to change this to match your own atpic account. # FTP will also need a .netrc file in your home directory # with an entry something like this: # # machine [your_acct].direct.atpic.com login [your_login] password [your_password] # # The pause between batches gives you a chance to move your pictures # out of the upload directory. The labels make it easy to put a goto # at the beginning of the script if you need to quit and come back later. # (Or you could just delete the part of your batch script that you had # already done. I like having the whole script for reference afterward.) # # The hash count is arbitrary; change as you like (or delete). # You might want a bigger number if you're uploading bigger files. # (Mine are mostly 3 megapix.) # # # Brent Chivers 2009/May/23 # # Put a label after each batch for goto's later. BDC 2009/Jun/22 # Don't print the labels as echo statements. BDC 2009/July/5 # Comments corrected and expanded. BDC 2009/Aug/13 ##! /bin/csh -fb # for setuid/setgid scripts (tsk) # set verbose # see commands before variable substitution # set echo # see commands after variable substitution unset histchars # get other users' history characters out of the way unalias * # get other users' .cshrc stuff out of the way ## set nonomatch # don't require wildcard matches # $0:t construction doesn't work! set cmd_name = $0 set cmd_name = $cmd_name:t # the name of this command if ($#argv == 0) then # no arguments provided echo "usage: $cmd_name search_directories" exit endif echo "# Run with [t]csh" echo "#" # find -ls: $7 = file size in bytes # $11 = file name /usr/bin/find $* -type f -ls | /usr/bin/awk '\ BEGIN { limit = 100000000 ; batch = 0 ; all_files = 0 ; all_bytes = 0 ; \ files = 0 ; bytes = 0 ; \ printf "/usr/bin/ftp u3160.direct.atpic.com << aInTnOmOrE\n" ; \ printf "bin\n" ; \ printf "hash 16384\n" } \ { if ( (bytes + $7) > limit ) { \ printf ("bye\n") ; \ printf ("aInTnOmOrE\n") ; \ printf ("echo \"batch %s: %d files, %d bytes\"\n", ++batch, files, bytes) ; \ printf "echo \"----------------------------------------\"\n" \ printf "echo \"Press RETURN when ready to send next batch....\"\n" \ printf "set fermata = \$<\n" \ printf ("done%s:\n", batch) ; \ bytes = 0 ; files = 0 \ printf "/usr/bin/ftp u3160.direct.atpic.com << aInTnOmOrE\n" ; \ printf "bin\n" ; \ printf "hash 16384\n" }} \ { depth = split ($11, path, "/") ; \ printf ("put %s %s\n", $11, path[depth]) ; \ files++ ; all_files++ ; bytes += $7 ; all_bytes += $7 } \ END { printf ("bye\n") ; \ printf ("aInTnOmOrE\n") ; \ printf ("echo \"batch %s: %d files, %d bytes\"\n", ++batch, files, bytes) ; \ printf ("echo \"ALL DONE: %d total files, %d total bytes\"\n", all_files, all_bytes) }'