Your best friend for file transfer.

Fetch application logoFetch

Automator to download files changed yesterday (7 posts)

  • Started 1 year ago by Eric
  • Latest reply 1 year ago from Eric
  • Eric Member

    Hello!

    I just got Fetch because of it's seemless integration with Automator. Specifically, I'd like to use it to download files from a folder and its subfolders that were changed yesterday, maintaining the structure.

    I tried the following workflow:

    1. Get Specified Fetch Items (here I input the parent folder)
    2. Get Fetch Folder Contents (clicked on Repeat for each subfolder found)
    3. Filter Fetch Items (Modification Date is Yesterday
    4. Download Fetch Items to Downloads

    Currently, it seems like the script is downloading entire folders if a single file has changed AND then its also downloading the individual files separately.
    What I'd like it to do is just download the specific files changed, maintaining the directory structure. So, if in folder books/ I have files file_1, file_2, and file_3, where files file_1 and file_2 have changed, I should wind up with a folder in the Downloads folder books, with contents file_1 and file_2.

    Any thoughts on this would be appreciated.

    Thank you,

    Eric

    Posted 1 year ago #

  • Jim Matthews Administrator

    Hi,

    It would be pretty simple to modify the workflow to only download files: you would add another Filter Fetch Items action, configured to select for the item type of "File".

    Preserving the folder organization is more difficult. Do you know how many subfolders there are likely to be? Are new subfolders likely to appear?

    Thanks,

    Jim Matthews
    Fetch Softworks

    Posted 1 year ago #

  • Eric Member

    Regarding the folder structure, there will be a series of sub and sub-sub folders, all with parent directory books, each with an initial sub-directory that looks like book_1, book_2, etc. (these will be very slowly added to my site every couple of months so if I need to manually update my automator script each time I have a new book_# folder it's not a big deal). Then each of the book_# folders will have 6 subfolders such as:

    books/book_1/files
    books/book_1/book_sections

    Thanks for the quick reply and I look forward to your next response!

    -Eric

    Posted 1 year ago #

  • Jim Matthews Administrator

    Thanks for that additional information. I can't think of a way to use the Automator actions to do exactly what you've described, without having dozens of actions. So I'm wondering if there's a way to do something that'd be close enough.

    The Mirror command would make a local folder hierarchy look like the hierarchy on the server, only downloading the items that had changed since the last time you'd used the command. Would that serve your purpose?

    Thanks,

    Jim Matthews
    Fetch Softworks

    Posted 1 year ago #

  • Eric Member

    Jim,

    Thank you for getting back to me. After doing a bunch of googling, I've discovered the wonderful world of Applescript. And, using StackOverflow as a resource:

    http://stackoverflow.com/questions/14017511/applescript-and-fetch
    http://stackoverflow.com/questions/9325743/how-do-you-download-all-files-using-fetch-and-applescript

    (I see that you helped out on the second post!)

    I've been able to piece together a script that does almost exactly what I want. The script, with obscured login info is below:

    set loginName to "!!!!!!"
    set thePassword to "*******"
    set today to current date
    #create remote and local subfolders
    set remote_subfolders to {"/_thumbs/Images", "/_thumbs/Files", "/book_sections", "/images", "/files"}
    set local_subfolders to {":_thumbs:Images", ":_thumbs:Files", ":book_sections", ":images", ":files"}

    #repeat the process with as many book_id's as we like
    repeat with book_id from 1 to 3
    repeat with subfolder_i from 1 to count (remote_subfolders)
    set remote_subfolder to item subfolder_i of remote_subfolders
    set local_subfolder to item subfolder_i of local_subfolders
    set remotePath to "/public_html/books/book_" & book_id & remote_subfolder
    -- Create Local path
    set localStorage to "Macintosh HD:Applications:MAMP:htdocs:books" & ":book_" & book_id & local_subfolder
    -- Connect to FTP
    #set up a try block as not all books have all subfolders
    try
    tell application "Fetch"
    activate
    set tWindow to make new transfer window at beginning with properties {hostname:"173.248.191.37", username:loginName, password:thePassword, initial folder:remotePath}
    set props to properties of remote items of tWindow
    tell tWindow
    set localStorage to (localStorage as alias)
    #iterate through the files
    repeat with i from 1 to number of items in props
    # one of the items
    set this_item to item i of props
    #get its modification date
    set modDate to modification date of this_item
    # compare the date by using number of days
    set lastModified to ((today - modDate) div 86400) -- the number of days

    if lastModified is less than 1 then
    download remote file (name of this_item) to localStorage
    end if

    end repeat

    close tWindow

    end tell
    quit

    end tell
    #loop through the folders
    -- Open folder
    tell application "Finder"
    open localStorage
    end tell
    error
    #ignore it if it doesn't exist on the remote server
    end try

    end repeat
    #loop through the books
    end repeat

    The 2 remaining details are:
    1) Right now Fetch is creating versions of local files that already exist. Is there anyway to overwrite them?
    2) My current script has me opening up a connection to the server on each iteration. Might there be a way to do this just once?

    Thank you,

    Eric

    Posted 1 year ago #

  • Jim Matthews Administrator

    Hi,

    Glad you found that script! You can check the "Overwrite files with conflicting names" in the Download section of Preferences. To minimize the number of connections, replace the "set tWindow to make new transfer window" line with something like:

    open url "ftp://" & loginName & ":" & thePassword & "@173.248.191.37/" & remotePath"
    set tWindow to transfer window 1

    Then Fetch will reuse the connection.

    Thanks,

    Jim Matthews
    Fetch Softworks

    Posted 1 year ago #

  • Eric Member

    Thanks Jim! This was just what I needed.

    -Eric

    Posted 1 year ago #

Reply

  • Or nickname, if you prefer.
  • This will be kept confidential.
  • This is to ensure that you’re a person, not a spambot.