如何使用 Fetch 和 applescript 下载所有文件?
我有以下脚本(经过修改以删除任何私人信息)。
-- 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
当我运行脚本时,以下行失败。
download every remote item to beginning of alias localStorage
我得到的错误如下:
错误“获取错误:无法获取窗口的每个远程项目(传输窗口 ID 232280960)。”窗口每个远程项的编号 -1728(传输窗口 id 232280960)
有谁知道错误意味着什么或如何修复它?我尝试过 Fetch 网站,但运气不佳。顺便说一句,“Fetch”是 Fetch FTP 客户端。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您应该检查您生成的
remotePath
是否确实存在(例如,通过添加log
语句,例如log tWindow's Remote items
并查看在脚本编辑器的事件日志中查看是否能够获取这些)。如果路径正确,我认为问题在于您正在使用
download
命令并引用列表对象(每个远程项目...
)。在文档中,该命令需要单个项目的说明符:这就是为什么您需要循环访问这些项目。 下面的代码片段非常适合我:
First you should check that the
remotePath
that you're generating really exists (e.g. by adding alog
statement such aslog tWindow's remote items
and 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
download
command 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:
将列表传递给
下载
没有问题。但原始代码存在两个问题:tell
块将所包含的命令定向到通用window
对象,而不是传输窗口
,并且通用window
对象不包含远程项目。download
命令的to
参数应该是别名,而不是插入位置(例如beginning of ...
)。这应该有效:
There's no problem passing a list to
download
. But there are two problems with the original code:tell
block directs the enclosed commands to a genericwindow
object, rather than atransfer window
, and the genericwindow
object does not contain remote items.download
command'sto
parameter should be an alias, not an insertion location (e.g.beginning of ...
).This should work: