开发者

Applescript download files from Http server sporadic results

开发者 https://www.devze.com 2023-04-05 14:31 出处:网络
I wrote a script that downloads files from an Http server, but the results are very sporadic. If I run it three times in a row, it might work twice and error once or not work at all and return differe

I wrote a script that downloads files from an Http server, but the results are very sporadic. If I run it three times in a row, it might work twice and error once or not work at all and return different errors.

Some of the errors I am getting are:

Error with downloading target URL (-609) Url Access Scripting got an error: Connection is invalid.

Error with downloading target URL (-31040) URL Access Scripting got an error: An error of type -31040 has occurred.

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 (" & ErrorN开发者_如何转开发umber & ")" message ErrorMessage
end try

Is there a better way to download files via AppleScript or is my coding bad?


Ahhh, thanks for the preview! I'm originally a Philadelphian and still passionate about Philly sports. I hope I'm not helping a Falcons fan. At least not this week! ;)

Anyway your code looks fine although URLAccessScripting is not the most reliable way to download. Actually as of 10.7 it's no longer even is included with the OS. Curl is an alternative and usually stable. You won't get a progress window with it though. Try this. See if it's more stable. It will tell you when it's finished.

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

精彩评论

暂无评论...
验证码 换一张
取 消