storme Posted December 22, 2010 Share Posted December 22, 2010 G'day all This is annoying me at the moment as I can't find a solution. I'm trying to download updates from a site (driverpacks.net). To get the torrent files you click on a link that looks like http://driverpacks.net/driverpacks/windows/xp/x86/mass-storage/10.11/download/torrent yet the file downloaded is http://driverpacks.net/driverpacks/windows/xp/x86/mass-storage/10.11/download/torrent/DP_MassStorage_wnt5_x86-32_1011.torrent I'd like to download using their name but the closest I can come is Local $hDownload = InetGet("http://driverpacks.net/driverpacks/windows/xp/x86/mass-storage/10.11/download/torrent",@ScriptDir & "\test.torrent") If @error Then MsgBox(0, "ERROR:", "Download Failed") EndIf I'd like to get the REAL filename so I can compare it agsainst existing files so I don't redownload files I already have. Thanks for any help you can offer. John Morrison aka Storm-E Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E Link to comment Share on other sites More sharing options...
fett8802 Posted December 22, 2010 Share Posted December 22, 2010 This won't download the file for you, you'll have to write that code. But this will identify the file name for you. You could run something like this before downloading the file to check to see if you already had it: Dim $lArray $URL = "http://driverpacks.net/driverpacks/windows/xp/x86/mass-storage/10.11/download/torrent/DP_MassStorage_wnt5_x86-32_1011.torrent" $lArray = StringSplit($URL, "/") $File_Name = $lArray[UBound($lArray)-1] MsgBox(0,"File Name Is...",$File_Name) That identified the file for me. -Fett [sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub] Link to comment Share on other sites More sharing options...
Richard Robertson Posted December 22, 2010 Share Posted December 22, 2010 You misunderstood what he wanted fett8802. To get the filename of a redirect, you'll have to read the HTTP stream manually or use a library that handles that. It may be a redirect and it may also load as an attachment. If it's an attachment, you'd read the name in the response header that says 'Content-Disposition: attachment;filename="nameoffile"'. The nameoffile part is the part you are wanting to read. Link to comment Share on other sites More sharing options...
trancexx Posted December 22, 2010 Share Posted December 22, 2010 (edited) You can use WinHttp.au3 for that what Richard Robertson suggested: #include "WinHttp.au3" ; Open needed handles Global $hOpen = _WinHttpOpen() Global $hConnect = _WinHttpConnect($hOpen, "driverpacks.net") ; Specify the reguest: Global $hRequest = _WinHttpOpenRequest($hConnect, Default, "driverpacks/windows/xp/x86/mass-storage/10.11/download/torrent") ; Send request _WinHttpSendRequest($hRequest) ; Wait for the response _WinHttpReceiveResponse($hRequest) Global $sHeader ; If there is data available... If _WinHttpQueryDataAvailable($hRequest) Then $sHeader = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_CONTENT_DISPOSITION) ;Or maybe: ;$sHeader = _WinHttpQueryHeaders($hRequest, BitOR($WINHTTP_QUERY_RAW_HEADERS_CRLF, $WINHTTP_QUERY_CUSTOM), "Content-Disposition") ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ; Display retrieved header ConsoleWrite($sHeader & @CRLF) MsgBox(0, "Header", $sHeader) Edited December 22, 2010 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
storme Posted December 23, 2010 Author Share Posted December 23, 2010 You can use WinHttp.au3 for that what Richard Robertson suggested:<SNIP>Thanks to BOTH of you!That code is exactly what I was looking for and works perfectly.. Now I can use a simple FileExists check instead of extracting version numbers from the url and a lot of spaghetti code.THANKS! Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E Link to comment Share on other sites More sharing options...
Yashied Posted December 23, 2010 Share Posted December 23, 2010 Without WinHTTP UDF. expandcollapse popupConsoleWrite(_HTTPGetResponse('http://driverpacks.net/driverpacks/windows/xp/x86/mass-storage/10.11/download/torrent') & @CR) Func _HTTPGetResponse($sUrl) Local $Error, $Socket, $Recv = '' Local $Host = StringRegExpReplace($sUrl, '.*://(.*?)/.*', '\1') Local $Page = StringRegExpReplace($sUrl, '.*://.*?(/.*)', '\1') Local $Send = 'HEAD ' & $Page & ' HTTP/1.1' & @CRLF & _ 'Host: ' & $Host & @CRLF & _ 'User-Agent: AutoIt/' & @AutoItVersion & ' (Windows; U; Windows NT 5.1; en-US; rv:1.8.1)' & @CRLF & _ 'Referer: ' & $Host & @CRLF & _ 'Connection: close' & @CRLF & @CRLF TCPStartup() If @error Then Return SetError(@error, 0, '') EndIf $IP = TCPNameToIP($Host) If @error Then Return SetError(@error, TCPShutdown(), '') EndIf $Socket = TCPConnect($IP, 80) If @error Then Return SetError(@error, TCPShutdown(), '') EndIf If Not TCPSend($Socket, $Send) Then Return SetError(@error, TCPCloseSocket($Socket) + TCPShutdown(), '') EndIf Do $Recv &= TCPRecv($Socket, 16) Until @error If Not $Recv Then $Error = @error Else $Error = 0 EndIf TCPCloseSocket($Socket) TCPShutdown() Return SetError($Error, 2, $Recv) EndFunc ;==>_HTTPGetResponse My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
storme Posted December 25, 2010 Author Share Posted December 25, 2010 Without WinHTTP UDF.Thanks Yashied that will do perfectly for my app.WinHttp.au3 is more flexable BUT as this is the only thing I need (I hope) I like the slimer code.THANKS! Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E 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