automated ftp action

I have an folder action which is designed to ftp a file or files to a specified place, the issue I have with this script is that, it does not send any files if they have been updated. It does not seem to look at the modified time. I need it to run the script each time a file is modified or added. The script is shown below. Any help fixing this issue is greatly appreciated.:slight_smile:

property NIXLB : "
"

on adding folder items to this_folder after receiving added_items
	
	set userName to "insertname"
	set userPassword to "insertpasswd"
	set hostName to "host"
	set remoteDir to "/folder/folder/folder"
	
	tell application "Finder"
		repeat with i from 1 to count of items of added_items
			tell application "Finder"
				set localFile to POSIX path of (item i of added_items)
				set fileName to item -1 of my explode("/", localFile)
				set remoteFile to (remoteDir & fileName) as string
				do shell script "ftp -n ftp://" & userName & ":" & userPassword & "@" & hostName & " << EOF" & NIXLB & "put " & localFile & space & remoteFile & NIXLB & "bye" & NIXLB & "EOF"
				move file (item i of added_items) as string to folder "Sent" of startup disk
			end tell
		end repeat
	end tell
end adding folder items to

on explode(delim, theString)
	if theString is "" then
		error "No path defined"
	else
		set od to text item delimiters of AppleScript
		set text item delimiters of AppleScript to delim
		set thelist to every text item of theString as list
		set text item delimiters of AppleScript to od
		return thelist
	end if
end explode

Model: any mac runniing os X
Browser: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.7) Gecko/20050416
Operating System: Mac OS X (10.4)

As the function name implies, the “on adding folder items” event only gets fired when items are added to the folder. Modifications don’t trigger it. One workaround I’ve used is to have a Delete-and-Resave script inside the source application that deletes the old version and then saves the new version, which then triggers the action. Is that an option for you?

not really, as the files are pdf’s, and there can be quite a few that are modified. I suppose I could put a condition at the beginning that looks for a filename of the incoming file, and if it finds it, move the current one to the trash. The only problem is, I do not know how that would fit into this code, as a friend wrote this for me. Can you shed any light on where or even if this would work.

Browser: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8a6) Gecko/20050111
Operating System: Mac OS X (10.4)

OK, on second read I realize I’m confused. I was about to suggest using a two-folder Outbox/Sent approach, so that nothing in the Outbox is ever getting modified, but when I look at your code I see you’re already doing that. So let’s go back to the beginning. Are your files getting moved to the Sent folder? If so, they wouldn’t still be in the target folder. So what is getting “modified”, when?

apologies in the late reply.

I have removed the code that move the file, as now we are modifying files which need to stay in the same folder they came from. If I move the files into a folder, if I add a pdf with the same filename, will it overwrite the existing file, or would it fail. If this way would work, then I could modify my script and do what you suggest with an In folder and Out folder.

Thanks for any help or input
:slight_smile: