Setting up OS9 script to ftp in OS X

I wrote a workhorse of an ftp script that worked perfectly as an OS 9 folder action. Dropping JPGs into it uploaded to my site appropriately.

Problem is, new PB17" w/Panther 10.3 - I do NOT know how to set up or alter the original script to work in new OS - can anyone help me?!?

Here’s the original script:

on adding folder items to thisFolder after receiving fileList
set ftpURL to “ftp://username:password@yourwebsite.com/youruploadareahere/
repeat with i in fileList
tell application “Finder” to set thisFileType to the file type of i
try
tell application “URL Access Scripting”
activate
if thisFileType is “TEXT” then
upload i to ftpURL replacing yes with progress and authentication
else
– delete the return between “binhexing” and “and” in the next line
upload i to ftpURL replacing yes with authentication without binhexing
end if
end tell
on error errMsg number errNum
display dialog (errNum as string) & ": " & errMsg
end try
end repeat
tell application “URL Access Scripting” to quit
end adding folder items to

Any thoughts?
Thank you in advance for any assistance you can give me,
Greg.

Does this script fail to work in 10.3? If so, does it result in an error?

– Rob

I have the script attached to a folder as a folder action.

Upon placing new items into the folder, nothing is happening.
So no error.

I’m assuming that I have connected the script correctly to the folder - this process too is odd for me in OS 10.3.

So the first thing I need to do is make sure my script is attached properly?
Should it be sending me an error?

Remember, the script initiates on an added file, so not sure how else to test it…

  • Greg.

Hi Greg,

Here’s a page from Apple that explains how to configure folder actions. Your script appears to have adequate error trapping (try, on error, end try) so if the script is failing, you should get a dialog that provides feedback.

– Rob

Ok, I followed the Apple instructions on installing folder actions…

Somehow I was able to apply my script from the finder, didn’t originally do it this way.

Also, I did not append script with .scpt suffix.
I resaved the script as an .scpt appended filename and it appeared to run a trst and displayed the following result:

-50: URL Sctipging got an error: Parameter error

This is all that it gives me. I do not know what parameter is in error.
Also, oddly enough, when I had my script visible in Folder Actions Setup application, I could not edit my script. Upon reading Apple’s description on how to add my own script to pop uplist, I had already saved my renamed .scpt appended script into the folder “Folder Actions” - and there it was on the pop up list. Progress.

But, upon dropping a new file into that Folder Action connected folder on my desktop, I get the same error:

-50:URL Scripting got an error: Parameter error

Any thoughts?
Seems like I’m much closer to solution, as in the script is kicking in on item being added to folder…

Where from here?

Sincerely,
Greg.

I don’t know what the problem is. I just tested the script on my machine (OS X 10.2.8) and it works fine. I don’t have access to Panther but I’ve seen reports that URL Access Scripting is somewhat buggy and unreliable. Since your code works in Jaguar, I suspect that the reports might be true.

– Rob

Did you try the running part of the code that does the upload from a Script Editor window? First check to see if the syntax works there. If you are still having problem, I recommend using cURL (command-line utility). It doesn’t let you use a progress bar (well, if you run it from AS, that is), but it is very reliable. I’ve got a simple handler that may help at http://www.danshockley.com/codebits.php

Let me know if you need help. I’ve given up on URLAS, since it had so many bugs earlier in OS X (it could not POST forms at all), and the command-line tools are so fast and reliable, and have many more options.

Krioni,

Thank you for your input and reply.

I have never used such a script.
What are the areas I need to alter per my own settings.

Say my username is “username” and password is “password” and my server location is “myserver.com/web

I have a folder located on my desktop named “LiveDesign” that I want to hook the folder action to.

Can you show me the way…?

Thank you so much in advance for any help you can provide.

Sincerely,
Greg.

Then you would need to copy the text of the entire handler (the “on simpleFtpUpload(remoteURL, macFilePath, userName, userPasswd)” line through the “end simpleFtpUpload” line) from my page athttp://www.danshockley.com/codebits.php, and include the following where you want the upload to occur:


simpleFtpUpload("ftp://myserver.com/web", "DriveX:Users:YOU:Desktop:TEMP:some'dir:person's ploy", "username", "password")

That, of course, is if the file you want to upload is at DriveX, etc.

Based on the code you posted earlier, you’d want to do the following:

ORIGINAL CODE SECTION:


set ftpURL to "ftp://username:password@yourwebsite.com/youruploadareahere/"
repeat with i in fileList
	tell application "Finder" to set thisFileType to the file type of i
	try
		tell application "URL Access Scripting"
			activate
			if thisFileType is "TEXT" then
				upload i to ftpURL replacing yes with progress and authentication
			else
				-- delete the return between "binhexing" and "and" in the next line 
				upload i to ftpURL replacing yes with authentication without binhexing
			end if
		end tell
	end try
end repeat

CODE USING CURL:


set ftpURL to "ftp://yourwebsite.com/youruploadareahere/" -- note that the username/password are no longer in the URL
set userName to "username"
set userPassword to "password"


repeat with i in fileList
	tell application "Finder" to set thisFileType to the file type of i
	try
		simpleFtpUpload(ftpURL, i, userName, userPassword)
		-- note that simpleFtpUpload expects a Mac-style path, not a POSIX path
		--note also that cURL should handle the upload method, and does not do binhexing
	on error errMsg number errNum
		display dialog (errNum as string) & ": " & errMsg
	end try
	
end repeat

You could also check the size of what was uploaded by changing the simpleFtpUpload line to the following:


set fileSizeUploaded to simpleFtpUpload(ftpURL, i, userName, userPassword)

and then checking how mush was uploaded later in the script.

Hope this helps.