Jump to content

File not downloading...


mdwerne
 Share

Go to solution Solved by Gianni,

Recommended Posts

So I'm attempting to download a file that may have a new name that changes every day. I can parse the file name but for some reason my script just hangs or I never get the downloaded file. If I paste my download link, from the 'ClipPut', into a browser, it works perfectly. Below is what I have so far, can anyone see what nuance I'm missing?

Thanks,

-Mike

#include <IE.au3>

Global $SequenceNumber

GetFileName()

Download()

Exit

Func GetFileName()
    Local $oIE = _IECreate("http://www.symantec.com/security_response/definitions/download/detail.jsp?gid=sonar", 0, 0)
    Local $sString = _IEBodyReadHTML($oIE)

    Local $iPosSeqStart = StringInStr($sString, 'http://definitions.symantec.com/defs/sonar/')
    Local $iPosSeqEnd = StringInStr($sString, '">', 0, 1, $iPosSeqStart)
    $SequenceNumber = (StringMid($sString, $iPosSeqStart + 43, $iPosSeqEnd - $iPosSeqStart - 43) & @CRLF)
    _IEQuit($oIE)
    MsgBox(0, "Download Information:", "DefFile: " & $SequenceNumber & @CRLF & "DownloadPath: " & "http://definitions.symantec.com/defs/sonar/" & $SequenceNumber)
    ClipPut("http://definitions.symantec.com/defs/sonar/" & $SequenceNumber)
EndFunc   ;==>GetFileName


Func Download()
    ; Advanced example - downloading in the background
    Local $hDownload = InetGet("http://definitions.symantec.com/defs/sonar/" & $SequenceNumber, @ScriptDir & "\" & $SequenceNumber, 1, 1)
    Do
        Sleep(250)
    Until InetGetInfo($hDownload, 2) ; Check if the download is complete.
    Local $nBytes = InetGetInfo($hDownload, 0)
    InetClose($hDownload) ; Close the handle to release resources.
    MsgBox(0, "", "Bytes read: " & $nBytes)
EndFunc   ;==>Download
Edited by mdwerne
Link to comment
Share on other sites

I used this function in the past. I don't know why, but if the local file already existed, it would not download and overwrite it.  I found that testing for the existence of the local file and deleting it if found, first, and the function worked.  It may not be what's happening in your case.  Also the bug may have been fixed as I don't have the latest AutoIt.  But it shouldn't take long to try the work-around.

Link to comment
Share on other sites

  • Solution

the $SequenceNumber variable contains 2 invisible characters at the end,
chr(10) and chr(13) that cause the InetGet() function to fail,
to remove that characters use the StringStripWS() function like this, and it will download the file.

Local $hDownload = InetGet("http://definitions.symantec.com/defs/sonar/" & $SequenceNumber, @ScriptDir & "\" & StringStripWS($SequenceNumber,2), 1, 1)

bye

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

@MilesAhead - Thanks for the reply and suggestion, but as long as I'm an admin on the box, which I am, the file overwrites the old one just fine.

@PincoPanco - DUDE!!! (assuming you're a dude ;) ) you're da bomb!!

That was it exactly!!

I mistakenly left the " & @CRLF" at the end of the $SequenceNumber variable.

This bad: $SequenceNumber = (StringMid($sString, $iPosSeqStart + 43, $iPosSeqEnd - $iPosSeqStart - 43) & @CRLF)

This good: $SequenceNumber = (StringMid($sString, $iPosSeqStart + 43, $iPosSeqEnd - $iPosSeqStart - 43))

Once I removed the extra '& @CRLF' all was well and I didn't need to strip the white space.

Thanks for taking the time to troubleshoot this for me. :thumbsup:

-Mike

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...