Sync Script

Of course I’m super new to Applescript, and I have spent several days lurking around here trying to find my way,

I need a script that will mount an ftp volume, sync with a folder on that ftp volume, unmount the volume, and close (Applescript) Oh and all this has to happen without user input and in the background.

I’m feel like I’m pretty close, but I still have a few questions, first you will see in my script that I have finder asking for the location. I don’t want that I want to put the location in the script but every time I do this I get more errors. ( I have been grabbing the folder, and dropping it into the script, as an alias) is there a better way to do this?

then the script tries to connect and mount the ftp server, if this does not succeed after 3 tries (no internet connection found) I would like the whole script to close quietly without errors.

the next part I have working pretty well, the script goes into the ftp copies the files not found on the local machine. then it is supposed to move files found on the local machine (TargetFldr) not found on the ftp (SourceFldr) to an Archive folder (on the local machine) but I get an alias error.

then I want it to unmount the Ftp volume.

FYI this is to happen on a remote kiosk while the machine is in use so I cant have any errors pop up and ruin the display.

thank you for any help…

 
set TargetFldr to (choose folder with prompt "Where is the target folder?")
set SourceFldr to (choose folder with prompt "Where is the source folder?")
set Archive to (choose folder with prompt "Where is the Archive folder?")

repeat 3 times
	try
		mount volume "ftp://user:password@server" -- if this succeeds, the internet is up.
		exit repeat
	on error -- no internet
		delay 300 -- delay 5 minutes
	end try
end repeat

tell application "Finder"
	set SourceContents to list folder SourceFldr
	set TargetContents to list folder TargetFldr
	
	repeat with x in SourceContents
		if x is not in TargetContents then
			duplicate alias ((SourceFldr as text) & x) to TargetFldr with replacing
		end if
	end repeat
	
	repeat with x in TargetContents
		if x is not in SourceContents then
			move alias ((TargetContents as text) & x) to Archive with replacing
		end if
	end repeat
end tell

eject disk "ftp://user:password@server"

Browser: Firefox 2.0.0.10
Operating System: Mac OS X (10.5)

Hi,

I recommend to use the shell (curl for downloading and mv for moving)
this works totally without the Finder


property serverPath : "[url=ftp://ftp.myDomain.com/parentDir/]ftp.myDomain.com/parentDir/[/url]"
property user_name : "user"
property pass_word : "¢¢¢¢"
property folderList : {"pub", "test"}


set TargetFldr to (choose folder with prompt "Where is the target folder?")
set SourceFldr to choose from list folderList with prompt "choose the source folder?" as text
set Archive to (choose folder with prompt "Where is the Archive folder?")
if SourceFldr is "false" then return
set sourcePOSIX to (serverPath & SourceFldr & "/")
set archivePOSIX to POSIX path of Archive
set TargetContents to list folder TargetFldr
set targetPOSIX to POSIX path of TargetFldr
set SourceContents to curl_readDirectory(sourcePOSIX)
if SourceContents is false then return

repeat with x in (get paragraphs of SourceContents)
	if x does not start with "." and x is not in TargetContents then curl_download(sourcePOSIX & x, targetPOSIX & x)
end repeat

repeat with x in TargetContents
	if x is not in SourceContents then move_File(targetPOSIX & x, archivePOSIX & x)
end repeat

on curl_download(source, dest)
	do shell script "/usr/bin/curl -o " & quoted form of dest & " -u " & user_name & ":" & pass_word & " " & quoted form of source
end curl_download

on curl_readDirectory(_path)
	try
		do shell script "usr/bin/curl -l " & _path & " -u " & user_name & ":" & pass_word
	on error
		return false
	end try
end curl_readDirectory

on move_File(source, dest)
	do shell script "/bin/mv " & quoted form of source & " " & quoted form of dest
end move_File

thank you for replying, thats great. One question is there a way to actually hide the password or encrypt it so if someone gets a hold of the script they will not have the password or the even better the user too?

If you leave the user_name and pass_word properties empty (with an empty string) you get the normal authentication window

thanks again, but remember this is an unmanned remote kiosk so the password has to be stored on the local machine but i would like to have it secure…