Jump to content

[Solved] File Downloading through Browser, but not Script


Recommended Posts

Edit: The solution! Maybe?

 

I need to download an image from a website using AutoIt but the download, when viewed in a text editor, does not appear to be the same as if I had downloaded it from a web browser.

Could anyone help me figure out why this is happening?

I've already tried _INetGetSource, InetGet, _IENavigate, wget, this, and a few .bat and .vbs scripts.

 

Example Code:

#include <Inet.au3>
Local $source = _INetGetSource("http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a")
Local $newfile = FileOpen(@ScriptDir & "\test.txt", 2)
FileWrite($newfile, $source)
FileClose($newfile)

Image URL: http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a

Screenshot attached.

Screenshot_60.png

Edited by hunte922
Link to comment
Share on other sites

I got some bizarre results, until i used binary mode flag in fileopen.

$sReturn = BinaryToString(InetRead("http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a", 8))
$hFile = FileOpen("test.png", 2+16)
FileWrite($hFile, $sReturn)
FileClose($hFile)

this works for me anyways

Link to comment
Share on other sites

9 minutes ago, Muhammad_Awais_Sharif said:

I have same result on both from Autoit and Browser (Text Editor Notepade++)

I just ran the script again and I am still getting the same results. Screenshot attached when viewing the downloaded file in Notepad++.

3 minutes ago, genius257 said:

I got some bizarre results, until i used binary mode flag in fileopen.

That code gives me the same incorrect result.

Screenshot_61.png

Edited by hunte922
Link to comment
Share on other sites

Maybe your cache?

$sReturn = InetRead("http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a", 8+1)
$hFile = FileOpen("test.png", 2+16)
FileWrite($hFile, $sReturn)
FileClose($hFile)

All i did was add the flag INET_FORCERELOAD

I've just tested my script on another pc, no problems there either.

Link to comment
Share on other sites

I was able to replicate your bug. But now it seems i can't undo it ^^'

Maybe it's a result of too many requests i a short time-span to the AmazonS3 server.

It's not the first time I've had an issue like that...

I will try running the script when i wake up and let you know :)

Link to comment
Share on other sites

Hello. What's wrong with this way?

InetGet("http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a","test.txt")

Saludos

Link to comment
Share on other sites

So i tried again just now, and it works fine again. The error seems to be related to too many server request within a time-frame. So i would suggest checking the downloaded file for a valid image-format and if not wait at least 1hour before trying again.

Link to comment
Share on other sites

Please try this

HttpSetUserAgent("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)")
$sReturn = BinaryToString(InetRead("http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a", 8))
$hFile = FileOpen("test.png", 2+16)
FileWrite($hFile, $sReturn)
FileClose($hFile)

Edit
10 times downloaded and still working :)

Edited by mikell
Link to comment
Share on other sites

On 6/10/2016 at 6:27 PM, mikell said:

10 times downloaded and still working

I ran my test codes at least 100times in under 1 hour before it started getting weird with the results.

Link to comment
Share on other sites

On 10/6/2016 at 11:27 AM, mikell said:

Please try this

HttpSetUserAgent("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)")
$sReturn = BinaryToString(InetRead("http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a", 8))
$hFile = FileOpen("test.png", 2+16)
FileWrite($hFile, $sReturn)
FileClose($hFile)

Edit
10 times downloaded and still working :)

 

9 minutes ago, genius257 said:

I ran my test codes at least 100times in under 1 hour before it started getting weird with the results.

I got it to work. The link to the solution is in the original post.

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...