I’d like a script that emails me whenever a customer drops new files into a directory on an ftp server.
A folder action should be the obvious solution, but it doesn’t work, because Finder doesn’t update the directory unless I unmount and remount it… which kills the folder action. Is there another way to force the folder to refresh the list of its contents?
Are Finder ftp services still as bodgy as they used to be, or should this work?
you can do it in a very elegant way with curl
Adjust the parameters and save the script as a stay open application
--the server parameters
property ftpserver : "[url=ftp://ftp.myServer.com]ftp.myServer.com[/url]"
property ftppath : "/path/to/directory/"
property server_username : "username"
property server_password : "¢¢¢¢¢"
--the e-mail parameters
property myaccount : "John Doe <john@doe.com>"
property theSubject : "mySubject"
property recipName : "Henry Smith"
property recipAddress : "henry@smith.com"
property theContent : "there is a new file"
property lastDir : {}
property interval : 5 * minutes
on run
checkDirectory()
end run
on idle
checkDirectory()
return interval
end idle
on checkDirectory()
set theCommand to "curl -l " & ftpserver & ftppath & " -u " & server_username & ":" & server_password
set currentDir to paragraphs of (do shell script theCommand)
if currentDir is not lastDir then sendEmail()
copy currentDir to lastDir
end checkDirectory
on sendEmail()
tell application "Mail"
set newMessage to make new outgoing message with properties {visible:true, subject:theSubject, content:theContent & return & return}
tell newMessage
set sender to myaccount
make new to recipient at end of to recipients with properties {name:recipName, address:recipAddress}
if theSignature is not "" then set message signature to theSignature
end tell
activate
send newMessage
end tell
end sendEmail
this is the first time I’ve used curl - how do I get it to return a list of files in the directory? (timestamps and file sizes would be nice too). It seems to only return the index.html file of the directory I point it to, or generates a 404 if no index.html is found.