I’m sufficiently more confused after an entire morning of unsuccessful attempts.
I’m in need of a “watch folder” that will FTP any new files for me automatically. I’m exporting up to 20 .mov files from Final Cut Pro daily to this FTP location. I want to export them to a specified local folder, have them transferred, and preferably deleted if successfully transferred via FTP.
Using an Automator plugin I’m able to SORT OF get this to work with Automator (http://www.editkid.com/upload_to_ftp/) There are 2 problems with this: 1) I can’t get folder actions to trigger. I’ve set up this Automator script with the folder actions enabled and it won’t trigger. I can run the Automator manually and it works great though. 2) There isn’t any way to do conditions. If the file name exists on the FTP server already you can’t have it take action, display a message, etc.
So my next step was to try using Applescript so that I could build in conditions. If the file exists, skip it for the time being but display a message that this file needs further attention, or a “Transfer Successful” message if all goes well. The folder that these .mov files will be put into will never change, so I don’t want the Applescript to prompt me to pick a folder (as I’m seeing in all the script examples I’ve come across).
Sadly after hours of playing with this I really don’t even have any code that I can post to ask for assistance on. In all reality, I’m looking for help from the ground up!
Any assistance you can offer is GREATLY appreciated and will reduce the stress my head has right now…
Thank you
Browser: Firefox 3.5.9
Operating System: Mac OS X (10.6)
Here is something that can help, it’s only version 1, so I may want to improve on it. Set up this script with a folder via folder action script and presto, your ready:
property uploadftp : ""
on adding folder items to this_folder after receiving added_items
if uploadftp is "" then set uploadftp to text returned of (display dialog "What do you want to upload to?" default answer "ftp://username:password123@00.00.00.00/dir/content/")
set thelist to ""
repeat with i in added_items
set thelist to thelist & return & i & ","
try
do shell script "curl -T " & quoted form of POSIX path of i & space & quoted form of uploadftp
on error e number n
display dialog "Error: " & e & "Number: " & n
end try
end repeat
display dialog "Items received: " & (count added_items) & return & "Folder: " & POSIX path of this_folder & return & "Items:" & return & return & thelist
end adding folder items to
Dylan,
I appreciate your post. I’m coming up with either no luck or me being confused though sadly.
So I put this into the AppleScript Editor, save it as a .scpt and use “Enable Folder Actions” to attach this to my watch folder, correct?
I’ve changed the FTP info (user-name, password, path)
Upon adding an item to the watch folder, I get nothing. No display message, and nothing sent to the FTP server. Within AppleScript Editor I also get nothing. If I hit the “Run” button nothing happens, no events/replies/result messages.
Any ideas? I appreciate your help and by the looks of it, your script is doing the majority of what I’m in need of! The only additional thing I’d be looking for is to delete the successfully transferred files.
You have probably done something wrong. I am going to take you on it Step by Step.
- Save the script.
- Put the script in ~/Library/Scripts
- Create a folder and click “Folder Action Setup…”
- You should get a window like this and you should click on the plus button on the left and add the folder, then click the plus button on the right and add the script.
Also, you should have anything returning when you run the script – no commands were called.
Dylan,
I tried what you listed (which is the same as I had done in the first place) and still no luck. But then I tried it on one of our other machines that will be set up with this feature once we get it worked out, and just like you say, it works slick as can be!
So are the bugs I need to get worked out yet:
- figure out why folder actions won’t work on my primary machine (and yes, the Enable box is checked)
- Have the script delete the successfully transferred files
- If this script tries to FTP a file name that exists on the FTP server, it first gives an error (ugly, but thats ok). But then it gives me a dialog box saying that it successfully transferred the files. However, it doesn’t transfer any files at all as they exist already and it won’t overwrite them. So this is working fine (as I don’t want the ability to overwrite existing files) but the dialog is reporting incorrectly.
Any further help you can offer is greatly appreciated.
I’ll get to your problem. Now I have to go, so maybe later in the day…
Well… It works OK for me. I don’t know what else to say. I do have this to stop the error:
property uploadftp : ""
on adding folder items to this_folder after receiving added_items
if uploadftp is "" then set uploadftp to text returned of (display dialog "What do you want to upload to?" default answer "ftp://username:password123@00.00.00.00/dir/content/")
tell uploadftp to if it does not end with "/" then set uploadftp to (uploadftp & "/")
set thelist to ""
repeat with i in added_items
try
do shell script "curl " & uploadftp & (name of (get info for i))
set err404 to true
on error e
if e contains "curl: (9) Server denied you to change to the given directory" then
set err404 to false
end if
end try
try
if err404 then
do shell script "curl -T " & quoted form of POSIX path of i & space & quoted form of uploadftp
end if
set thelist to thelist & return & i & ","
on error e number n
display dialog "Error: " & e & "Number: " & n
end try
end repeat
display dialog "Items received: " & (name of (get info for added_items)) & return & "Folder: " & POSIX path of this_folder & return & "Items Uploaded:" & return & return & thelist
end adding folder items to