Jump to content

InetGet


anyday
 Share

Recommended Posts

hey guys, need some help with InetGet function. Im trying to download a .pdf file from my companys website in my script.

Here is the code i have so far

whats going on is, i have a treeview with a list of different file's that are on the website. i first wanted to just have the PDF open up in a COM IE window, which works fine. but then i figured i would have the script download the file the first time the user clicked on the treeview item and then the next time user clicked on the item it would show the local pdf (trying to save on companys server connection) so i put this code to try to accomplish this but the inetget fails everytime. any ideas?

Case $trvFORMS_3
        ;If FileExists(@ScriptDir & '\TN\company\Auto\filename.pdf') Then
        ;   $Obj.Navigate(@ScriptDir & '\TN\company\Auto\filename.pdf')
        ;Else
                If InetGet('https://website/webform/PDFs/filename.pdf', @ScriptDir & '\TN\company\Auto\filename.pdf') Then
                    MsgBox(4096, "Success", "")
                Else
                    MsgBox(4096, "Failure", "")
                EndIf
Link to comment
Share on other sites

use fileexist..

If FileExist(@ScriptDir & '\TN\company\Auto\filename.pdf') then
      ShellExecute (@ScriptDir & '\TN\company\Auto\filename.pdf')
  Else
      InetGet('https://website/webform/PDFs/filename.pdf', @ScriptDir & '\TN\company\Auto\filename.pdf')
  EndIf
Link to comment
Share on other sites

even though its https:// there is no username password required. no firewalls or anything blocking, i can pull it up in my internet explorer , its shows the pdf file.. Could it not be working for some reason because it is a pdf?

Link to comment
Share on other sites

I'd do this- show the user whats happening.... Especially if its a large PDF.

#include <WindowsConstants.au3>
$window = GUICreate  ("Parent", 800, 600)
$picture = GUICtrlCreatePic ("", 10, 10, 780, 580)
GUISetState (@SW_SHOW)
$ret = InetGetProgress("http://signa5.com/personal/images/editedrm8.jpg", @ScriptDir & "\test.jpg", $window)

GUICtrlSetImage ($picture, @ScriptDir & "\test.jpg")

While 1
    $nMsg = GUIGetMsg ()
    Switch $nMsg
        Case -3;exit
            Exit
    EndSwitch
WEnd

Func InetGetProgress($url, $to, $hwnd)
    $size = InetGetSize($url)
    $filename = StringRight($url, StringInStr($url, "/", 0, -1))
    InetGet($url, $to, 0, 1)
    $GUI = GUICreate("Downloading... " & $filename, 230, 100, 285, 250, $WS_POPUP, $WS_EX_MDICHILD, $hwnd)
    $Label1 = GUICtrlCreateLabel("Downloading " & $filename & "", 8, 8, 214, 37)
    $Progress1 = GUICtrlCreateProgress(8, 52, 214, 17)
    GUICtrlSetLimit(-1, 100, 0)
    GUISetState(@SW_SHOW)
    While @InetGetActive
        $Progress = Round((@InetGetBytesRead/$size)*100, 0)
        GUICtrlSetData ($Progress1, $Progress)
        Sleep (50)
    WEnd
    GUISwitch ($hwnd)
    GUIDelete ($GUI)
EndFunc

Cheers,

Brett

EDIT: No chance of getting the link is there? Otherwise I'll upload a sample PDF file to my site... :P

Edited by BrettF
Link to comment
Share on other sites

well i tried your code, and replaced your url with mine. it caused the program to lock up, never showed a progress bar like it does on the .jpg in your link.

yea sorry can give out the url..

but here is the filename im trying to download

SA1088%209-07.pdf

could it have something to do with the % in the filename?

Edited by anyday
Link to comment
Share on other sites

I'm uploading a sample PDF to my site now. Not HTTPS, but should tell us if the PDF is the problem (unlikely).

Then I'll create an IE object to display the PDF for you.

It could be that part of your script as well.

EDIT

Sample PDF Works fine.

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <IE.au3>

$oIE = _IECreateEmbedded ()
$window = GUICreate  ("Parent", 800, 600)
$picture = GUICtrlCreateObj ($oIE, 10, 10, 780, 580)
GUICtrlSetState ($picture, $GUI_HIDE)
GUISetState (@SW_SHOW)
$ret = InetGetProgress("http://signa5.com/other/AutoITHelp/Sample.pdf", @ScriptDir & "\SAMPLE.pdf", $window)

GUICtrlSetState ($picture, $GUI_SHOW)
_IENavigate ($oIE, @ScriptDir & "\SAMPLE.pdf")

While 1
    $nMsg = GUIGetMsg ()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func InetGetProgress($url, $to, $hwnd)
    $size = InetGetSize($url)
    $filename = StringRight($url, StringInStr($url, "/", 0, -1))
    InetGet($url, $to, 0, 1)
    $GUI = GUICreate("Downloading... " & $filename, 230, 100, 285, 250, $WS_POPUP, $WS_EX_MDICHILD, $hwnd)
    $Label1 = GUICtrlCreateLabel("Downloading " & $filename & "", 8, 8, 214, 37)
    $Progress1 = GUICtrlCreateProgress(8, 52, 214, 17)
    GUICtrlSetLimit(-1, 100, 0)
    GUISetState(@SW_SHOW)
    While @InetGetActive
        $Progress = Round((@InetGetBytesRead/$size)*100, 0)
        GUICtrlSetData ($Progress1, $Progress)
        Sleep (50)
    WEnd
    GUISwitch ($hwnd)
    GUIDelete ($GUI)
EndFunc

Will try with your updated file name.

EDIT 2:

Works a charm!

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <IE.au3>

$oIE = _IECreateEmbedded ()
$window = GUICreate  ("Parent", 800, 600)
$picture = GUICtrlCreateObj ($oIE, 10, 10, 780, 580)
GUICtrlSetState ($picture, $GUI_HIDE)
GUISetState (@SW_SHOW)
$ret = InetGetProgress("http://signa5.com/other/AutoITHelp/SA1088%25209-07.pdf", @ScriptDir & "\SAMPLE.pdf", $window)

GUICtrlSetState ($picture, $GUI_SHOW)
_IENavigate ($oIE, @ScriptDir & "\SAMPLE.pdf")

While 1
    $nMsg = GUIGetMsg ()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func InetGetProgress($url, $to, $hwnd)
    $size = InetGetSize($url)
    $filename = StringRight($url, StringInStr($url, "/", 0, -1))
    InetGet($url, $to, 0, 1)
    $GUI = GUICreate("Downloading... " & $filename, 230, 100, 285, 250, $WS_POPUP, $WS_EX_MDICHILD, $hwnd)
    $Label1 = GUICtrlCreateLabel("Downloading " & $filename & "", 8, 8, 214, 37)
    $Progress1 = GUICtrlCreateProgress(8, 52, 214, 17)
    GUICtrlSetLimit(-1, 100, 0)
    GUISetState(@SW_SHOW)
    While @InetGetActive
        $Progress = Round((@InetGetBytesRead/$size)*100, 0)
        GUICtrlSetData ($Progress1, $Progress)
        Sleep (50)
    WEnd
    GUISwitch ($hwnd)
    GUIDelete ($GUI)
EndFunc
Edited by BrettF
Link to comment
Share on other sites

ok, i tried your code with my url with no luck.

then i downloaded the pdf from my url and put it on my server and tried again with no luck.

i renamed the file on my server from SA1088%209-07.pdf to SA1088209-07.pdf and it worked, renamed it back to SA1088%209-07.pdf and again no luck.

so maybe the filename is the problem?

EDIT:

i viewed the source of the html file on the url im trying to use. it links the pdf like this PDFs/SA1088 9-07.pdf but in the browser it shows SA1088%9-07.pdf, i dont know if this is the browsers way of dealing with a space in a filename and i cant figure out if this is part of the problem?

Edited by anyday
Link to comment
Share on other sites

Fixed with OP over PM. Appears that the https causes the example script to stop responding.

Anyone got any ideas why a normal HTTP request is OK for a PDF?

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...