Problem reading remote file

Hi All,

This is a part of a script that had been working fine then all of a sudden it gets an error. This reads a text file from my server to get the version number of a script to see if it needs to be updated. My server is running 10.4.11 and this seems like it may have started after a recent security update.


set versionFile to "Server HD:Users:updateserver:versions:COPSM_version.txt"
	tell application "System Events" of machine "eppc://UpdateServer:password@64.207.236.146:3031"
		set latestVersion to read versionFile
		return latestVersion
	end tell

this should return “1.3.1” but instead I get an error (-1708)

System Events got an error: file “Server HD:Users:updateserver:versions:COPSM_version.txt” doesn’t understand the <> message.

Any ideas??

Thanks,
Mark

Hi,

are you talking about a remote volume (over bonjour) or a shared volume (over afp)?
BTW: read is a part of Standard Additions and doesn’t need any target application

Hi Stefan,

The file is on the boot volume of my server (64.207.236.146) so I’m sending a remote apple event (port 3031) from the script to read the file “COPSM_version.txt” in the folder “versions” which is in the user UpdateServer. I don’t think it is bonjour or AFP. You can try the script, it is all correct. It’s strange that a week ago this script worked fine and I have made no changes to the script.

Thanks,
Mark

remote apple events seems to be working on that machine as I have another script that launches an app on the same machine and that works fine. It is referencing a different account but the same server.

as versionFile is just a literal string path, you should you this syntax

set latestVersion to read file versionFile

I tried this


set versionFile to "Server HD:Users:updateserver:versions:COPSM_version.txt"
tell application "System Events" of machine "eppc://UpdateServer:password@64.207.236.146:3031"
	set latestVersion to read file versionFile
	return latestVersion
end tell

but it still says that the file “Server HD:Users:updateserver:versions:COPSM_version.txt” doesn’t understand the read message.

??? :frowning:

try this please, you have to change the property lines


property user_name : "UpdateServer" -- admin username
property pass_word : "password" -- admin password
property uid : "501" -- user id of remote user
property host_name : "64.207.236.146:3031" -- or the "MyServer.local" bonjour name

set versionFile to "Server HD:Users:updateserver:versions:COPSM_version.txt"
set s to "eppc://" & user_name & ":" & pass_word & "@" & host_name & "/Finder?uid=" & uid

using terms from application "Finder"
	tell application s
		set latestVersion to read file versionFile
	end tell
end using terms from

System Events doesn’t run by default on the remote machine, using the Finder to send the Remote Event is more reliable

I tried this.


property user_name : "UpdateServer" -- admin username
property pass_word : "password" -- admin password
property uid : "1027" -- user id of remote user
property host_name : "64.207.236.146:3031" -- or the "MyServer.local" bonjour name

set versionFile to "Server HD:Users:updateserver:versions:COPSM_version.txt"
set s to "eppc://" & user_name & ":" & pass_word & "@" & host_name & "/Finder?uid=" & uid

using terms from application "Finder"
	tell application s
		set latestVersion to read file versionFile
	end tell
end using terms from

the only change was uid to 1027 and now I get “Finder got an error: Cannot find process on host”

do you get the same error when you run it. FYI: I set the password for the user to “password” for testing so run it from your end and see if you get the same error.

Thanks a bunch,
Mark

Of course I tested both scripts successfully, but I used the bonjour name and the parameters of my local network
I got the same error running your script. Do Remote Apple Events actually work over the internet?

Edit: Maybe the user iD isn’t correct.
I tested all user IDs form 1000 to 1030 with the routine below,
if the user is logged in, it returns the path to desktop.
There is no match at all, but user ID 501 works


on check_user(eppc)
	using terms from application "Finder"
		try
			tell application eppc to return (desktop as string)
		on error
			return false
		end try
	end using terms from
end check_user

I haven’t had any trouble until now and I’ve used this script for months. This is a function in the script that will check for updates to the script if it has been 7 days since the last check. If I update the script I change the number in the text file so when people use the script it will read the number from the text file and compare it to the version number in the script they have and if they don’t match will prompt them to download the update. When I was writing the script I tested it from home to be sure it worked outside my local network and it has always been spot on.

The userid for the user UpdateServer is 1027

Since I ran a software update on the server a few days ago I’ve been having this problem and it always hangs on the “read” command either from my LAN or the internet. I wasn’t sure if the security update caused some change in remote apple events. Since the script hasn’t been changed logic would tell me that something on the server has so I guess I’ll review my server settings.

Since it doesn’t seem to like “read” I’ve tried “open file” just to test.


property user_name : "UpdateServer" -- admin username
property pass_word : "password" -- admin password
property uid : "1027" -- user id of remote user
property host_name : "64.207.236.146:3031" -- or the "MyServer.local" bonjour name

set versionFile to "Server HD:Users:updateserver:versions:COPSM_version.txt"
set s to "eppc://" & user_name & ":" & pass_word & "@" & host_name & "/Finder?uid=" & uid

using terms from application "Finder"
	tell application s
		open file versionFile
		--set latestVersion to entire contents of versionFile
		--set latestVersion to read file versionFile
	end tell
end using terms from

When I run the above script the file “Server HD:Users:updateserver:versions:COPSM_version.txt” opens in TextEdit on the remote machine. Why won’t it read the contents of the file? The fact that the file opens tells me remote events are working.

Thanks for your help!
Mark

Maybe Apple changed the habit of Standard Additions for security reasons.

I tested a few things but I don’t want to poke further on your server.
Try something like this, it checks if TextEdit is open, if not it opens it and reads the text file


.
set versionFile to "Server HD:Users:updateserver:versions:COPSM_version.txt"
set s to "eppc://" & user_name & ":" & pass_word & "@" & host_name & "/?uid=" & uid

tell application "Finder" of machine s
	using terms from application "Finder"
		if "TextEdit" is not in (get name of processes) then open application file id "com.apple.TextEdit"
	end using terms from
end tell
tell application "TextEdit" of machine s
	using terms from application "TextEdit"
		open versionFile
		set t to text of document 1
		quit
	end using terms from
end tell

It looks like this works.


property user_name : "UpdateServer" -- admin username
property pass_word : "password" -- admin password
property uid : "501" -- user id of remote user
property host_name : "64.207.236.146:3031" -- or the "MyServer.local" bonjour name

set versionFile to "Server HD:Users:updateserver:versions:COPSM_version.txt"
set s to "eppc://" & user_name & ":" & pass_word & "@" & host_name & "/Finder?uid=" & uid

using terms from application "Finder"
	tell application s
		open file versionFile
		set latestVersion to read file versionFile
	end tell
end using terms from

The uid did need to be 501 even though in Workgroup Manager it shows the user “UpdateServer” as 1027 and changing the uid in the above script yielded the exact error I was getting earlier. The recent security must have changed something with reading remote files. Seems to work fine now.

Thanks As Always,
Mark

This worked also but is slower.


property user_name : "UpdateServer" -- admin username
property pass_word : "password" -- admin password
property uid : "501" -- user id of remote user
property host_name : "64.207.236.146:3031" -- or the "MyServer.local" bonjour name
set versionFile to "Server HD:Users:updateserver:versions:COPSM_version.txt"
set s to "eppc://" & user_name & ":" & pass_word & "@" & host_name & "/?uid=" & uid

tell application "Finder" of machine s
	using terms from application "Finder"
		if "TextEdit" is not in (get name of processes) then open application file id "com.apple.TextEdit"
	end using terms from
end tell
tell application "TextEdit" of machine s
	using terms from application "TextEdit"
		open file versionFile
		set t to text of document 1
		quit
	end using terms from
end tell