2011-09-16 40 views
0

我寫了一個腳本,從Http服務器下載文件,但結果是非常零星的。如果我連續運行它三次,它可能會運行兩次,錯誤一次或根本不工作,並返回不同的錯誤。從Http服務器零星的結果Applescript下載文件

一些我收到的錯誤是:

錯誤與下載目標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下載文件或者我的代碼不好?

回答

1

啊,感謝您的預覽!我原本是費城人,對費城體育仍然充滿熱情。我希望我不幫助獵鷹隊的球迷。至少不是這周! ;)

無論如何,你的代碼看起來不錯,儘管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 
+0

哈哈,我其實是爲獵鷹隊工作。會是一個偉大的遊戲!這工作完美,並感謝讓我知道URLAccessScripting正在消失!我在不同的地方看到了一些評論,但沒有完全意識到。 – RGilkes

+0

很高興能幫到你!是的,它應該是一場偉大的比賽,祝你好運......除了週日晚上約3小時! – regulus6633