Your best friend for file transfer.Fetch
Download then Read file (2 posts)
- Started 7 years ago by trinkel
- Latest reply 7 years ago from Jim Matthews
I'm writing a script for clients accessing our server. I would like to have the script download and read a preferences file. I've tried different combinations of copy and download commands and POSIX vs. Mac paths. Now I'm just confused.
My latest try is something like:
set theDEST to "ftp://XXXX:@ftp.myhost.com/"
set tmpFilePathName to "/tmp"
set remotePrefs to ".GFTPprefs"
set localPrefs to tmpFilePathName & "/" & remotePrefs
display dialog remotePrefs & return & localPrefs
tell application "Fetch"
open url theDEST with immediate return
copy remote file remotePrefs to localPrefs
display dialog remotePrefs
display dialog localPrefs
When I run this the first display dialog (before the copy) returns
The Fetch tell seems to run OK, but I don't think anything is downloaded.
The display dialog after the Fetch block returns remotePrefs OK but localPrefs gets an error:
Fetch got an error: Can't make remote file ".GFTPprefs" into type string.
Kind of weird since this is outside of the Fetch block and localPrefs was correct before the copy command.
I know at one point the file did download, but I don't remember what the difference was. I did, however, get a similar error message when I tried to read or do anything with localPrefs.
OK, so where is my logic failing here. Or if it's easier, forget that and just let me know how it should be. Since this will be distributed to various clients (who do own Fetch by the way - just thought I'd throw that in) I probably shouldn't hard code something like "Macintosh HD".
Jim Matthews Administrator
I see 3 things that you'll want to change in your script:
1) You don't want the "with immediate return" parameter on the open url event. When you specify immediate return, AppleScript goes on to execute the next statement before the open url is really done. That can cause the copy remote file statement to fail because the transfer window has not finished opening.
By the way, you can combine the open url and copy remote file statements into one, like this:
copy remote file (theDEST & remotePrefs) to ...
2) The destination parameter for the copy command should refer to a folder, not a file. You can tell Fetch what folder to put the download in, but you can't currently tell Fetch what to name the downloaded file -- it will get the same name it has on the server. So you want tmpFilePathName (i.e. "/tmp"), not tmpFilePathName & "/" & remotePrefs (i.e. "/tmp/.GFTPrefs").
3) The destination parameter for the copy command has to be a folder reference, not just a pathname string. Since you have POSIX paths, you want something like this:
copy remote file (theDEST & remotePrefs) to POSIX file tmpFilePathName
Please let me know if that doesn't work.
- Page 1