Watch an ftp directory?

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?

thanks

Luke Jaeger

Hi Luke,

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

thank you!

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.

LJ

the last character of the path must be a slash otherwise you get the parent directory
Try this standalone line

do shell script "curl -l [url=ftp://ftp.server.com/path/]ftp.server.com/path/[/url] -u user:pass"

With the curl command it’s only possible to read the name of the files (AFAIK)

when I try this:

do shell script "curl -l vomax.com/customer_uploads/ -u username:password"

I get a 403.

When I put an index.html file into that directory, the curl script returns the contents of the file. I can’t get a directory listing either way.

isn’t it ftp.vomax.com or something like this?

no, the syntax I used is the only thing that works … otherwise I get an error.

if I try "curl ftp.vomax.com … "
or “curl ftp://ftp.vomax.com …”

I get error 7 - “couldn’t connect to host” (even though I am logging in successfully).

Thanks for bothering with all this, by the way …

Can you access the directory with a FTP client like Fetch or Transmit?
If you succeed, just use the same syntax with curl

hey it works now!

just had to disable epsv.

thanks a ton!

LJ

Glad to read this :slight_smile: