Copying one file, 2 locations one using FTP

Hey everyone,

after lurking for a few days knowing nothing about applescript I’ve sort of frankensteined my code using other’s incredible work. I am however having some problems with the droplet.

The task:

Part 1. Drop one file (QT Mov) onto a applescript app copy to 2 locations.

Part 2. Force lower case for file names.

The Problem:

Part 1. This works when I use a duplicate command to 2 mounted volumes. However if I do not want to mount the second volume but send it via FTP I have inital success copying the file however every time after the additional run the file will not copy.

Part 2. I just can’t get this to work

The Code:

  FTP Upload Droplet
Jonathan del Strother

-- Set these properties to suit your needs:
property storageFolder1 : "Macintosh HD:Users:aa:Desktop:1"
property userName : "Omneon"
property password : "Omneon"
property server : ""
property targetDir : "/fs0/FCP"

-- You don't need to touch these:
property nl : ASCII character 10
property currentDir : ""

on unixPath(path_components)
	set filepath to "/"
	repeat with i from 2 to ((length of path_components) - 1) --Skip the first item (Macintosh HD) and the last (the filename)
		set filepath to filepath & ":" & item i of path_components
	end repeat
	return the POSIX path of filepath
end unixPath

on constructCommand(thisFile)
	set path_components to text items of (thisFile as string)
	set thisCommand to ""
	if (the last character of (thisFile as string) is ":") then
		--the 'file' is actually a folder
		-- Create the directory on the server, and cd into it.
		set dirName to item ((length of path_components) - 1) of path_components
		set thisCommand to "mkdir " & dirName & nl & "cd " & dirName & nl
		-- set up a new list of files, and recursively call this function
		tell application "Finder" to set subFiles to every item of thisFile
		repeat with thisSubFile in subFiles
			set thisCommand to thisCommand & constructCommand(thisSubFile)
		end repeat
		-- Move back out of the current directory.
		set thisCommand to thisCommand & "cd .." & nl
		--return the command to upload this file
		-- Need to change the local directory if necessary
		set filepath to unixPath(path_components)
		if (filepath is not equal to currentDir) then
			set thisCommand to thisCommand & "lcd \"" & filepath & "\"" & nl
			set currentDir to filepath
		end if
		set filename to last item of path_components
		set thisCommand to thisCommand & "send \"" & filename & "\"" & nl
		return thisCommand
	end if
end constructCommand

on open someFiles
	tell application "Finder"
			duplicate someFiles to storageFolder1 replacing yes
		on error errtext number errnum
			display dialog errtext buttons {"OK"} default button 1
		end try
	end tell
	--Store the original delimiters
	set originalDelims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ":"
	set command to "ftp -n " & server & " << eof > /tmp/ftpUploadLog
  		user " & userName & " " & password & "
		cd " & targetDir & nl & "
		binary" & nl
	--For each file, add its upload command to the rest.	
	repeat with thisFile in someFiles
		set command to command & constructCommand(thisFile)
	end repeat
	set command to command & "quit"
	--display dialog command
	-- This is where all of the above actually gets executed...
	do shell script (command)
	--and now, beep to show we're done.
	--Restore the original delimiters
	set AppleScript's text item delimiters to originalDelims
end open

Any insight into the process would be appreciated with either attempt. Ideally I’d like to do this in one droplet. Any direction to some resources would be equally appreciated!


Additionally if anyone thinks a duplicate will work better, If anyone knows how to mount an AFP silently so its hidden from the GUI and user but could be hit in the terminal that’d be a great solution.

Problem is I can’t install dev tools or anything, I need the script to just work regardless of which machine it’s on and if it’s been reformatted.