Free tech support / small logo


Tweaking FTP scripts to fine-tune their behavior

A reader writes:
I have your Wicked Cool book and love it. I am new at scripting and it is helping a ton. Question. I need a script to use the timestamp feature (ingenious by the way) of Script #83 but "get" the files from a remote server like Script #82. Do you have one modified in such a way?

Dave's Answer: I don't have a hybrid script, but the core piece you're talking about is this:
if [ ! -f $timestamp ] ; then
  # no timestamp file, upload all files
  for filename in *
  do 
    if [ -f "$filename" ] ; then
      echo "put -P \"$filename\"" >> $tempfile
      count=$(( $count + 1 ))
    fi
  done
else
  for filename in $(find . -newer $timestamp -type f -print)
  do 
    echo "put -P \"$filename\"" >> $tempfile
    count=$(( $count + 1 ))
  done
fi
If you're talking about script #82, then I surmise that you want to get the files rather than put them. So what happens if you just change the "put" to a "get" here? Well, there are two challenges. First off, your timestamp file might well now exist on the remote system (solved by doing an ftp 'get' before you proceed) and second, the list of files you want to grab aren't local anymore either. The latter is solved by generating a file listing (use "dir" in the ftp sequence), saving it, parsing it out (don't forget to include the last modified date/time), and then comparing each to the date/time of the timestamp file.

I admit, it's going to be quite a bit more work if you want to be really flexible in this solution, but given the speed of modern connections, it might just be easier to bulk "get" everything on the remote system regardless of the timestamp anyway.

However you solve it, good luck!









Subscribe!
Never miss another Q&A article! Click to subscribe: Add to Google Reader Add to My Yahoo! Subscribe in NewsGator RDF XML
Comments
Rather amazingly, there are no comments on this article yet.

I have something to say, now that you mention it, but ...
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you for all your efforts on this Web site by buying you a cup of coffee!

I do have a comment, now that you mention it!











Remember personal info?


Please note that I will never send you any unsolicited email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Recent Entries


Search
I Need Help!
Need Help? Ask Dave Taylor!


© 2002 - 2012 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.