I have the following script (modified to remove any private information).
-- This line is for testing.
set the clipboard to "1234567890"
set loginName to "username"
-- Password is stored in KeyChain (you need to do manually).
-- Create Remote path
set folderNumber to the clipboard as string
set subdir1 to character 1 of folderNumber
set subdir2 to character 2 of folderNumber
set remotePath to "/files/" & subdir1 & "/" & subdir2 & "/" & folderNumber
-- Create Local path
set homeFolder to (path to home folder) as string
set localPath to homeFolder & "LOCALSTORAGE" as string
set localStorage to localPath & ":" & folderNumber & ":" as string
-- Create Local file
tell application "Finder"
try
make new folder at localPath with properties {name:folderNumber}
on error e number n
-- Do nothing.
end try
end tell
-- Connect to FTP
tell application "Fetch"
activate
set tWindow to make new transfer window at beginning with properties {hostname:"ftpServerAddress", username:loginName, initial folder:remotePath}
tell window tWindow
download every remote item to beginning of alias localStorage
close window
end tell
quit
end tell
-- Open folder
tell application "Finder"
open localStorage
end tell
When I run the script the following line fails.
download every remote item to beginning of alias localStorage
The error I get is as follows:
error “Fetch got an error: Can’t get every remote item of window (transfer window id 232280960).” number -1728 from every remote item of window (transfer window id 232280960)
Does anyone know what the error means or how to fix it? I’ve tried the Fetch website without much luck. “Fetch” btw is the Fetch FTP client.
First you should check that the
remotePaththat you’re generating really exists (e.g. by adding alogstatement such aslog tWindow's remote itemsand looking up in the Script Editor’s event log whether it was able to get those).If the path is correct, I think the problem is that you’re using the
downloadcommand with a reference to a list object (every remote item...). In the documentation, the command expects a specifier of a single item:That’s why you need to loop through the items. The snippet below works perfectly for me: