anyday Posted October 13, 2008 Posted October 13, 2008 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
mikiutama Posted October 13, 2008 Posted October 13, 2008 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
anyday Posted October 13, 2008 Author Posted October 13, 2008 im not having a problem finding if the file exist, the actual inetget command does not work.
mikiutama Posted October 13, 2008 Posted October 13, 2008 maybe left any passwords for the https? or maybe thru ftp? any firewalls/AV blocking?
anyday Posted October 13, 2008 Author Posted October 13, 2008 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?
BrettF Posted October 13, 2008 Posted October 13, 2008 (edited) 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... Edited October 13, 2008 by BrettF Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
anyday Posted October 13, 2008 Author Posted October 13, 2008 (edited) 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 October 13, 2008 by anyday
BrettF Posted October 13, 2008 Posted October 13, 2008 (edited) 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. expandcollapse popup#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! expandcollapse popup#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 October 13, 2008 by BrettF Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
anyday Posted October 13, 2008 Author Posted October 13, 2008 (edited) 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 October 13, 2008 by anyday
BrettF Posted October 13, 2008 Posted October 13, 2008 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? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now