Applescript从Http服务器下载文件

Applescript从Http服务器下载文件,applescript,Applescript,我编写了一个从Http服务器下载文件的脚本,但结果非常零散。如果我连续运行三次,它可能会运行两次,出错一次,或者根本不工作,并返回不同的错误 我遇到的一些错误包括: 下载目标URL(-609)时出错 Url访问脚本出错:连接无效 下载目标URL(-31040)时出错 URL访问脚本出错:发生了类型为-31040的错误 try set theFileURL to "http://ftp2.nflfilmstv.com/filmsint/ftp-inet/Team/110915_game_p

我编写了一个从Http服务器下载文件的脚本,但结果非常零散。如果我连续运行三次,它可能会运行两次,出错一次,或者根本不工作,并返回不同的错误

我遇到的一些错误包括:

下载目标URL(-609)时出错 Url访问脚本出错:连接无效

下载目标URL(-31040)时出错 URL访问脚本出错:发生了类型为-31040的错误

try
    set theFileURL to "http://ftp2.nflfilmstv.com/filmsint/ftp-inet/Team/110915_game_preview_phi_atl_3200k.mp4" as text

    set TID to AppleScript's text item delimiters
    set AppleScript's text item delimiters to "/"
    set theFile to text item -1 of theFileURL
    set AppleScript's text item delimiters to TID

    set theFilePath to "Macintosh HD:Users:rgilkes:Desktop:" & theFile as text

    tell application "URL Access Scripting" to download theFileURL to file theFilePath with progress
    on error ErrorMessage number ErrorNumber
        display alert "Error with downloading target URL (" & ErrorNumber & ")" message ErrorMessage
end try

有没有更好的方法通过AppleScript下载文件?还是我的编码不好?

Ahhh,谢谢预览!我原来是费城人,对费城的体育运动仍然充满热情。我希望我不是在帮助一个猎鹰队的球迷。至少这周不行!;)

无论如何,您的代码看起来不错,尽管URLAccessScripting不是最可靠的下载方式。实际上,从10.7开始,它甚至不再包含在操作系统中。卷曲是另一种选择,通常是稳定的。不过,你不会得到一个进度窗口。试试这个。看看是否更稳定。它会告诉你什么时候完成

set theFileURL to "http://ftp2.nflfilmstv.com/filmsint/ftp-inet/Team/110915_game_preview_phi_atl_3200k.mp4"

set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
set theFile to text item -1 of theFileURL
set AppleScript's text item delimiters to TID

set theFilePath to (path to desktop as text) & theFile

try
    do shell script "curl " & quoted form of theFileURL & " -o " & quoted form of POSIX path of theFilePath
    display dialog "The download is finished!" buttons {"OK"} default button 1 with icon note giving up after 5
on error theError
    display dialog "Error downloading the file:" & return & theFile & return & return & theError buttons {"OK"} default button 1 with icon 0 giving up after 5
end try

哈哈,我实际上是为猎鹰队工作的。这将是一场精彩的比赛!这非常有效,谢谢你让我知道你不在了!!我在不同的地方看到了一些关于这方面的评论,但我并不完全清楚。很高兴我能帮上忙!是的,这应该是一场伟大的比赛,祝你好运。。。除了周日晚上的3个小时!