Foxhound Posted October 9, 2010 Share Posted October 9, 2010 Is there any way of using InetGet to get a file and save it to a particular directory without specifying a file name?I read up on a similar but unresolved issue here: http://www.autoitscript.com/forum/index.php?showtopic=113129the URL I need to download from varies ( the script reads a .dat file) so I can't always specify a file name with a correct extension for it. I just need it to automatically get a file and save it. I know if it's a direct link I could just pull the file name from the URL string, but like I said, the URLs vary and some are PHP.Is it possible? [quote]Quick YouTube To MP3 | Lyrics Finder | Internet Radio Player | GetWeather | TinyURLifier[/quote] Link to comment Share on other sites More sharing options...
martin Posted October 9, 2010 Share Posted October 9, 2010 Is there any way of using InetGet to get a file and save it to a particular directory without specifying a file name?I read up on a similar but unresolved issue here: http://www.autoitscript.com/forum/index.php?showtopic=113129the URL I need to download from varies ( the script reads a .dat file) so I can't always specify a file name with a correct extension for it. I just need it to automatically get a file and save it. I know if it's a direct link I could just pull the file name from the URL string, but like I said, the URLs vary and some are PHP.Is it possible?I would have guessed that if you change the working directory to the folder where you want the file to be saved then that is where it will go. But when I tried downloading a file, InetGet returned 0 so nothing downloaded. If I specify a file name then the download works so the optional file name isn't optional as far as I can tell. Using a folder name for the file name doesn't work either. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
LordJugag Posted October 9, 2010 Share Posted October 9, 2010 Hello... I tried to use: Case $tm_file _File() $url = "http://sub.domain.com/File.ini" ;source $folder = "C:\Local Folder\" ;destination folder InetGet($url,$folder & StringTrimLeft($url,StringInStr($url,"/",Default,-1))) ;stringinstr finds the last "/". Stringtrimleft trims all but the filename. Do not download... I tried to use and that: FileDelete(@TempDir & "\File.ini") InetGet("http://sub.domain.com/File.ini", @TempDir & "\File.inie", 1, 0) Do not download... What to do? What are reliable solutions? Link to comment Share on other sites More sharing options...
NinerSevenTango Posted October 9, 2010 Share Posted October 9, 2010 (edited) Try InetRead instead, see if that works (should be the same but returns binary data). If that doesn't work, re-check spelling on the url (you did make sure the file is there and that you can access it from your machine, right?). Try setting a variable with the command to get the return value. Try running the example script in the helpfile, if it works, look for what's different. And don't bump your posts for at least 24 hours or the admins will bump you. Edited October 9, 2010 by NinerSevenTango Link to comment Share on other sites More sharing options...
Tvern Posted October 9, 2010 Share Posted October 9, 2010 It'd help to have one, or all of the following: * A download location that we can use to test solutions. * Your code with any sensitive information replaced. * The source of a page that can be used to dowload one of these files with any sensitive information replaced. I'm not saying we'll find a solution based on that information, but it sure wouldn't hurt your chances. Link to comment Share on other sites More sharing options...
Foxhound Posted October 9, 2010 Author Share Posted October 9, 2010 Try InetRead instead, see if that works (should be the same but returns binary data).If that doesn't work, re-check spelling on the url (you did make sure the file is there and that you can access it from your machine, right?).Try setting a variable with the command to get the return value.Try running the example script in the helpfile, if it works, look for what's different.And don't bump your posts for at least 24 hours or the admins will bump you.Well here is an example of the URL:http://filehippo.com/download/file/c06ab2b89cc149fe35396acb8242cb65960465024a3088aff5482cc013ca3d21/There is nothing to pull out of this string. InetRead doesn't work for me, I don't think it saves it [quote]Quick YouTube To MP3 | Lyrics Finder | Internet Radio Player | GetWeather | TinyURLifier[/quote] Link to comment Share on other sites More sharing options...
Tvern Posted October 10, 2010 Share Posted October 10, 2010 (edited) I think those links are only valid for a short amount of time, or ar bound to a session. Tghe one you linked doesn't work for me anyways.I used the firefox plugin Live HTTP Headers to see what happens when downloading a filehippo file via the visible link with this result:expandcollapse popup;url entered http://www.filehippo.com/download/file/5f63c14fdd5fbf7d5c55a76295cd38e1c9af9cb5d5947f4d049287583d27f2a8/ ;my request GET /download/file/5f63c14fdd5fbf7d5c55a76295cd38e1c9af9cb5d5947f4d049287583d27f2a8/ HTTP/1.1 Host: www.filehippo.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; nl; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: nl,en-us;q=0.7,en;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Referer: http://www.filehippo.com/download_windows_7_codecs/download/40d57606f26fbdd6cf5882267507a6f8/ Cookie: FH_PreferredCulture=en-US; __utma=144473122.295445865.1286668771.1286668771.1286668771.1; __utmb=144473122.19.10.1286668771; __utmz=144473122.1286668771.1.1.utmcsr=autoitscript.com|utmccn=(referral)|utmcmd=referral|utmcct=/forum/index.php; FHSession=jjb3bx452aisrpr4aldkrb23; __utmc=144473122 ;server response HTTP/1.1 301 Moved Permanently Date: Sun, 10 Oct 2010 00:29:53 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET Content-Length: 0 Location: http://fs21.filehippo.com/7381/57cbd244c4ed4d998a9e22ea49214b71/Win7codecs_v265.exe Cache-Control: private Content-Type: text/html ---------------------------------------------------------- ;redirect url http://fs21.filehippo.com/7381/57cbd244c4ed4d998a9e22ea49214b71/Win7codecs_v265.exe ;redirect request GET /7381/57cbd244c4ed4d998a9e22ea49214b71/Win7codecs_v265.exe HTTP/1.1 Host: fs21.filehippo.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; nl; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: nl,en-us;q=0.7,en;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Referer: http://www.filehippo.com/download_windows_7_codecs/download/40d57606f26fbdd6cf5882267507a6f8/ Cookie: __utma=144473122.295445865.1286668771.1286668771.1286668771.1; __utmb=144473122.19.10.1286668771; __utmz=144473122.1286668771.1.1.utmcsr=autoitscript.com|utmccn=(referral)|utmcmd=referral|utmcct=/forum/index.php; __utmc=144473122 ;server response HTTP/1.1 200 OK Date: Sat, 09 Oct 2010 23:59:16 GMT Server: Apache/2 Last-Modified: Sat, 09 Oct 2010 05:26:43 GMT Etag: "64d0002-19b0e50-492285f5b2ac0" Accept-Ranges: bytes Content-Length: 26938960 Keep-Alive: timeout=1, max=100 Connection: Keep-Alive Content-Type: application/x-msdownloadAs you can see, you get redirected to the actual location of the file and I think that's the key to getting the filename. Only problem is that when I try to read the server response using the winhttp.au3 udf, it only returns the last response which doesn't give me the file name.I'm pretty new to this kind of stuff, so maibe someone else knows how to get the information of the redirect.Edit: Actually I got it. Give me a sec to write it out.This function returns the true file location for a given Filehippo url which will include the filename. It looks a lot more elaborate than it is because I went a bit overboard with the errorchecking and I had to close the open handles for each error. You'll need the WinHTTP UDF by trancexx.I think it would be nicest to do the file download with winhttp too and just make one big function that will mimic the behavior of InetGet, but you can also just run the function first and use the result with a standard InetGet. Hope this proves more usefull than my "contribution" to the other thread on the subject. expandcollapse popup#include "winhttp.au3" $sLocation = _GetTrueLocation("http://www.filehippo.com/download/file/59ef6f11d0f3ac0dc291c54670b4f99c7c79116f088ff979c331e41d5630d9f7/") ConsoleWrite($sLocation & @CRLF) Func _GetTrueLocation($sUrl) Local $aCracked = _WinHttpCrackUrl($sURL) If @error Then Return SetError(1,0,"") Local $hOpen = _WinHttpOpen() If @error Then Return SetError(2,0,"") Local $hConnect = _WinHttpConnect($hOpen,$aCracked[2]) If @error Then SetError(3,0,0) _WinHttpCloseHandle($hOpen) Return EndIf Local $hRequest = _WinHttpOpenRequest($hConnect, "GET", $aCracked[6]) If @error Then SetError(4,0,0) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Return EndIf _WinHttpSetOption($hRequest, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_DISABLE_REDIRECTS) If @error Then SetError(5,@error,0) _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Return EndIf _WinHttpSendRequest($hRequest) If @error Then SetError(6,0,0) _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Return EndIf _WinHttpReceiveResponse($hRequest) If @error Then SetError(7,0,0) _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Return EndIf Local $sHeader = _WinHttpQueryHeaders($hRequest) If @error Then SetError(8,0,0) _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Return EndIf $alocation = StringRegExp($sHeader,"Location: .*",1) If @error Then SetError(9,0,0) _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Return EndIf _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Return $alocation[0] EndFunc Edited October 10, 2010 by Tvern Link to comment Share on other sites More sharing options...
LordJugag Posted October 10, 2010 Share Posted October 10, 2010 (edited) It'd help to have one, or all of the following: * A download location that we can use to test solutions. * Your code with any sensitive information replaced. * The source of a page that can be used to dowload one of these files with any sensitive information replaced. I'm not saying we'll find a solution based on that information, but it sure wouldn't hurt your chances. Ok... my source... expandcollapse popup#NoTrayIcon #Include <INet.au3> #Include <String.au3> #include <GUIConstantsEx.au3> Global $oIE = ObjCreate("Shell.Explorer.2") Global $ini = @ScriptDir & "\Browser Log.ini" Global $db = @ScriptDir & "\Local Database.ini" Global $_Next Global $read_height = IniRead($ini, "DISPLAY", "HEIGHT", "") Global $read_width = IniRead($ini, "DISPLAY", "WIDTH", "") Global $read_homepage = IniRead($ini, "Settings", "Homepage", "") Global $read_starthomepage = IniRead($ini, "Settings", "StartHomepage", "") Global $read_firstrecruit = IniRead($ini, "RECOMMENDATION", "FAVORIT", "") If $read_height = "" Then IniWrite($ini, "DISPLAY", "HEIGHT", "600") IniWrite($ini, "DISPLAY", "WIDTH", "800") $read_height = 600 $read_width = 800 EndIf If $read_starthomepage = "" Then $read_starthomepage = "1" $read_homepage = "http://www.google.com" EndIf If $read_firstrecruit = "" Then IniWrite($ini, "RECOMMENDATION", "FAVORIT", "http://www.autoitscript.com") EndIf $iniread = IniRead($ini, "URL", "LAST URL", "") If $read_starthomepage = "0" Then $read_homepage = $iniread $gui_main = GUICreate("", $read_width, $read_height + 20, -1, -1, 0x04000000 + 0x00CF0000) $file_menu = GUICtrlCreateMenu("File") $fm_open = GUICtrlCreateMenuItem("Open", $file_menu) $fm_sep = GUICtrlCreateMenuItem("", $file_menu) $fm_print = GUICtrlCreateMenuItem("Print", $file_menu) $fm_sep = GUICtrlCreateMenuItem("", $file_menu) $fm_savas = GUICtrlCreateMenuItem("Save As", $file_menu) $fm_SaveSource = GUICtrlCreateMenuItem("Save Source", $file_menu) $fm_sep = GUICtrlCreateMenuItem("", $file_menu) $fm_exit = GUICtrlCreateMenuItem("Exit", $file_menu) $fav_menu = GUICtrlCreateMenu("Favorites") $fav1 = GUICtrlCreateMenuItem("Google", $fav_menu) $fav2 = GUICtrlCreateMenuItem("AutoIT", $fav_menu) $tool_menu = GUICtrlCreateMenu("Recommendation") $tm_recommendation = GUICtrlCreateMenuItem("Recommend", $tool_menu) $about_menu = GUICtrlCreateMenu("About") $am_about = GUICtrlCreateMenuItem("About", $about_menu) $gui_iewindow = GUICtrlCreateObj($oIE, 0, 0, $read_width, $read_height - 15) GUICtrlSetResizing($gui_iewindow, 0x0001) $status_bar = GUICtrlCreateLabel("Loading: " & $read_homepage & "...", 0, 584, $read_width, $read_height, BitOR(11, 0x1000)) GUISetState() AnimateTitle($gui_main, "Browser - Created by Justin Reno/Modified by LordJugag", 100) $oIE.Navigate ($read_homepage) While 1 WinSetTitle($gui_main, "", "Browser - Created by Justin Reno/Modified by LordJugag - " & $oIE.locationURL ()) If $oIE.Busy () Then $url = $oIE.LocationURL () _StatusChange("Loading: " & $url & "...") Else _StatusChange("Done.") EndIf $msg = GUIGetMsg(1) Switch $msg[0] Case - 3 $update = $oIE.LocationURL () IniWrite($ini, "URL", "LAST URL", $update) Exit ;File Menu Case $fm_open Local $file = FileOpenDialog("Browser : Select file", @ScriptDir, "All Files (*.*)") If @error <> 1 Then _StatusChange("Loading: " & $file & "...") $oIE.Navigate ($file) EndIf Case $fm_print $oIE.document.parentwindow.Print () Case $fm_savas $oIE.document.execCommand ("SaveAs") Case $fm_SaveSource $IE = _INetGetSource("" & $update & "") FileWrite(@DesktopDir & "\websource.html", $IE) MsgBox(0, "Browser", "Saved to desktop as websource.html") Case $fm_exit $update = $oIE.LocationURL () IniWrite($ini, "URL", "LAST URL", $update) Exit ;Favorites Menu Case $fav1 $oIE.Navigate ("http://www.google.com") Case $fav2 $oIE.Navigate ("http://www.autoitscript.com") ;Recruiter Menu Case $tm_recommendation _Recommendation() $url = "http://aorr.110mb.com/Local Database.ini" ;source $folder = "C:\Browser Database\" ;destination folder InetGet($url,$folder & StringTrimLeft($url,StringInStr($url,"/Local Database.ini",Default,-1))) ;stringinstr finds the last "/". Stringtrimleft trims all but the filename. ;About Menu Case $am_about MsgBox ( 0, 'About', 'Browser - version alpha' ) EndSwitch WEnd Func _StatusChange($message) GUICtrlSetData($status_bar, $message) EndFunc ;==>_StatusChange Func _Recommendation() $_Next = $_Next + 1 If $_Next > 9 Then GUICtrlSetState ( $tm_recommendation, $GUI_DISABLE ) MsgBox ( 0, 'Recommendation', 'Please try again later' ) EndIf ConsoleWrite ( "$_Next : " & $_Next & @Crlf ) Switch $_Next Case 1 $oIE.Navigate (IniRead($ini, "RECOMMENDATION", "FAVORIT", "")) Case 2 $oIE.Navigate (IniRead($db, "RECOMMENDATION", "RECOMMEND_1", "")) Case 3 $oIE.Navigate (IniRead($db, "RECOMMENDATION", "RECOMMEND_2", "")) Case 4 $oIE.Navigate (IniRead($db, "RECOMMENDATION", "RECOMMEND_3", "")) Case 5 $oIE.Navigate (IniRead($db, "RECOMMENDATION", "RECOMMEND_4", "")) Case 6 $oIE.Navigate (IniRead($db, "RECOMMENDATION", "RECOMMEND_5", "")) Case 7 $oIE.Navigate (IniRead($db, "RECOMMENDATION", "RECOMMEND_6", "")) Case 8 $oIE.Navigate (IniRead($db, "RECOMMENDATION", "RECOMMEND_7", "")) Case 9 $oIE.Navigate (IniRead($db, "RECOMMENDATION", "RECOMMEND_8", "")) EndSwitch EndFunc ;==>_Recommendation Func AnimateTitle($hGUI, $sTitle, $iBuf) $sTitle = StringSplit($sTitle, "") For $i = $iBuf To 0 Step - 1 WinSetTitle($hGUI, "", _StringRepeat(" ", $i) & $sTitle[1]) Next Local $s For $i = 1 To $sTitle[0] $s &= $sTitle[$i] WinSetTitle($hGUI, "", $s) Sleep(5) Next EndFunc ;==>AnimateTitle Download file is at http://aorr.110mb.com/Local Database.ini Edited October 10, 2010 by LordJugag Link to comment Share on other sites More sharing options...
Tvern Posted October 11, 2010 Share Posted October 11, 2010 @LordJugagWhen posing a new question, it's best to start a new topic. It wouldn't have been nice for the OP if his question was ignored and your's answered and I didn't even notice the additional question.Also: bumping within 24h is frowned upon.But while we're here:$url = "http://aorr.110mb.com/Local Database.ini" $folder = "C:\Browser Database\" If Not FileExists($folder) Then DirCreate($folder) ;InetGet doesn't create the destination folder for you. InetGet($url,$folder & StringTrimLeft($url,StringInStr($url,"/",Default,-1)))You need to make sure the target dir exists before writing to it. Another problem could be if the file already exists and is opened, so it cannot be overwritten. Link to comment Share on other sites More sharing options...
LordJugag Posted October 11, 2010 Share Posted October 11, 2010 Ok... thank you for solved with problema InetGet Now I've found it does not work... Global $db = @ScriptDir & "C:\Browser Database\Local Database.ini" The source below... Case X $oIE.Navigate (IniRead($db, "RECOMMENDATION", "RECOMMEND_X", "")) ... had to read the Local Database.ini and not work Link to comment Share on other sites More sharing options...
nekkutta Posted October 11, 2010 Share Posted October 11, 2010 You are combining the @scriptDir and a full filepath, try doing a msgbox(0,'',$db) to see what you are trying to IniRead() [size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size] Link to comment Share on other sites More sharing options...
LordJugag Posted October 11, 2010 Share Posted October 11, 2010 You are combining the @scriptDir and a full filepath, try doing a msgbox(0,'',$db) to see what you are trying to IniRead()lolozaur... message displays C:\Program Files\AutoIt3\ExamplesC:\Browser Database\Local Database.iniHow do I fix? Link to comment Share on other sites More sharing options...
nekkutta Posted October 11, 2010 Share Posted October 11, 2010 Global $db = @ScriptDir & "C:\Browser Database\Local Database.ini" you will want to remove the @ScriptDir & part [size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size] Link to comment Share on other sites More sharing options...
LordJugag Posted October 11, 2010 Share Posted October 11, 2010 Working! Thank you! Link to comment Share on other sites More sharing options...
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