Copy Files from a mounted network share to a folder in local hard disk

Hi Folks,

Im a newbie in the world apple script. I found this forum giving awsom help to all biginners.
My problem is: “I want to copy a file from a network share to my local folder. I’m able to mount the drive but i can’t copy. getting error like Can’t get file etc etc…”

My goal is to copy an ISO image from a network share to a local folder in hard disk. Also I want to rename that file to WIN.iso after copying ( or during copy to local folder). There are two shares a MAC and a WINDOWs share. I want to mount these two shares in a third MAC PC ( MAC OS X Server Ver 10.4.8)

Can I handle both Windows share mounting and MAC Share mounting using same funtion ?

The code snippent for Reading share informations from a text file and mounting share is…

set filePath to ((path to desktop as string) & "ServerList.txt") as alias
set txt to ReadAndListFile(filePath)
--Set Variables using the information in ServerList file
set Win_Server to searchAndReplace(item 2 of txt, "Server=", "")
set Win_Username to searchAndReplace(item 3 of txt, "Username=", "")
set Win_Password to searchAndReplace(item 4 of txt, "Password=", "")
set Win_SharePath to searchAndReplace(item 5 of txt, "SharePath=", "")

set Mac_Server to searchAndReplace(item 8 of txt, "Server=", "")
set Mac_Username to searchAndReplace(item 9 of txt, "Username=", "")
set Mac_Password to searchAndReplace(item 10 of txt, "Password=", "")
set Mac_SharePath to searchAndReplace(item 11 of txt, "SharePath=", "")

	tell application "Finder" to mount volume "smb://" & Win_Username & ":" & Win_Password & "@" & Win_Server & Win_SharePath
on error errtext number errnum
	if errnum = -55 then
		display dialog "Already Mounted"
	end if
end try

on ReadAndListFile(filePath)
	open for access filePath
	set txt to read filePath using delimiter return
	close access filePath
	return txt
end ReadAndListFile

on searchAndReplace(txt, srch, rpl)
	set oldtid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {srch}
	set temp to every text item of txt
	set AppleScript's text item delimiters to {rpl}
	set temp to (temp as string)
	set AppleScript's text item delimiters to oldtid
	return temp
end searchAndReplace

And the code snipped i used for copy a file from the drive is…

set dsk to (path to desktop)
tell application "Finder"
	set cd_name to "RELEASES"	
	set file_to_copy to (quoted form of POSIX path of ("Volumes:"& cd_name &"SourceFolder:MySourceFile.ISO"))
	set target_file to (quoted form of POSIX path of (dsk) & "MyDestinationFile.ISO")
	copy file file_to_copy to target_file
end tell

Thanks folks,

Hi Ajai,

this doesn’t work at all.
¢ Copy copies a value to an AppleScript variable, the command to copy files is move or duplicate
¢ AppleScript works with HFS paths (colon delimited)
¢ Full HFS paths start always with the name of the Volume (unlike the shell, which starts with /Volumes/)
¢ To copy and rename a file at the same time it’s better to use the shell (therefore the POSIX paths are perfect)

set dsk to path to desktop
set cd_name to "RELEASES"
set file_to_copy to quoted form of POSIX path of (cd_name & ":SourceFolder:MySourceFile.ISO")
set target_file to quoted form of (POSIX path of dsk & "MyDestinationFile.ISO")
do shell script "cp " & file_to_copy & space & target_file

Thanks stefan… thanks a lot…

This forum really rocks… :smiley: