Check FTP for new Files ?

I have a Webserver and made an ftp-server on it for 2 friends, so they can upload files to it (with username/password).

Is it possible to make an AppleScript that checks the folders of those 2 users for new files ?
And is it possible to make that script run automatically every hour or so ?

I’m new to those Script thingies…

Thanks and a happy new year !
Timo

Hey Timo,

open the scriptlet in your script editor and save it as an Application with the option “stay open”. Place it in your Applications directory (or wherever you want) and run it.

I’ve commented the source to give you some basic explanation, but don’t hesitate to post any additional questions here. For further information… well, MacScripter.net will prove to be a valuable resource, as you’ll see :slight_smile:

Regards,
danB


property ftp_url : "[url=ftp://ftp.yourserver.tld/path/to/dir]ftp.yourserver.tld/path/to/dir[/url]"
property ftp_user : "username"
property ftp_pass : "password"
property old_ftp_items : {} --this one stores a list of files that have already been "seen" on the server

on idle
	set new_ftp_items to ""
	set ftp_listing to do shell script "curl -l ftp://" & ftp_user & ":" & ftp_pass & "@" & ftp_url --obtain a listing of the dir using the 'curl' shell command
	set ftp_items to (get every paragraph of ftp_listing) -- this gives us the listing as an AppleScript list
	
	repeat with i from 1 to (count ftp_items) -- iterate over the items in the listing
		set j to ((item i of ftp_items) as text)
		
		(* if the current file is not in old_ftp_items, we add it to new_ftp_items and then to old_ftp_items (so that it won't show up as new when the script runs the next time *)
		if old_ftp_items does not contain j then
			set new_ftp_items to ((new_ftp_items & j & (return)) as text)
			set end of old_ftp_items to j
		end if
		
	end repeat
	
	--display a dialog with the new items if there are any
	if length of new_ftp_items > 0 then
		display dialog "The following items were added to the ftp folder: " & new_ftp_items buttons {"OK"} default button 1
	end if
	
	return 3600 --the return value of the "on idle" handler is the time in seconds until the next run
end idle

Model: iBook g3/800 14"
Browser: Safari 312.3.3
Operating System: Mac OS X (10.3.9)

Thanks a lot !
Works so far…Having some problems with the path to the exact folder I want to check, but I hope I will solve this.

Or…does he check subfolders as well ?
I tested it, but it doesn’t seem to check them.

Thanks again
Timo

Mornin’,

indeed, the script doesn’t check subfolders. It just obtains the FTP listing of a single dir (the one you specify). What problems do you have with the folder path?

Regards,
danB

Model: iBook g3/800 14"
Browser: Safari 312.3.3
Operating System: Mac OS X (10.3.9)