Jump to content



Photo

WinINet.au3 (FTP/HTTP/HTTPS/Gopher+)


  • Please log in to reply
104 replies to this topic

#1 -Ultima-

-Ultima-

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 267 posts

Posted 04 August 2008 - 01:37 AM

Purpose (MSDN - Windows Internet)
The Microsoft Windows Internet (WinINet) application programming interface (API) enables applications to access standard Internet protocols, such as FTP, Gopher, and HTTP. For ease of use, WinINet abstracts these protocols into a high-level interface.

Download

Attached File  WinINet_2010_01_02.zip   60.57K   3037 downloads
- Minor tweaks

Attached File  WinINet_2008_09_13.zip   61.27K   1949 downloads
- Added _WinINet_Shutdown
- Added _WinINet_Startup
- Fixed _WinINet_CreateUrlCacheGroup
- Fixed _WinINet_FindFirstUrlCacheEntryEx
- Fixed _WinINet_FindNextUrlCacheEntryEx
- Fixed _WinINet_FtpCommand
- Fixed _WinINet_InternetFindNextFile
- Fixed _WinINet_SetUrlCacheEntryGroup
- Changed _WinINet_GetUrlCacheGroupAttribute (returns array instead of DllStruct)
- Many examples added (mostly complete for FTP functions)

Attached File  WinINet_2008_08_22.zip   56.46K   528 downloads
- Fixed INTERNET_CACHE_ENTRY_INFO-related functions (they return an array now rather than the raw structure)
- Added examples for _WinINet_FindFirstUrlCacheEntry() and _WinINet_CreateUrlCacheEntry()

Attached File  WinINet_2008_08_16.zip   53.75K   355 downloads
- Fixed some string/buffer length issues

Attached File  WinINet_2008_08_11.zip   53.74K   371 downloads
- Added _WinINet_FindCloseUrlCache
- Added _WinINet_FindFirstUrlCacheEntry
- Added _WinINet_FindFirstUrlCacheEntryEx
- Added _WinINet_FindFirstUrlCacheGroup
- Added _WinINet_FindNextUrlCacheEntry
- Added _WinINet_FindNextUrlCacheEntryEx
- Added _WinINet_FindNextUrlCacheGroup
- Added _WinINet_InternetCrackUrl
- Added _WinINet_InternetCreateUrl

Attached File  WinINet.zip   49.71K   374 downloads
- Initial release

Function List
Plain Text         
IMPLEMENTED =========== _WinINet_CommitUrlCacheEntry _WinINet_CreateUrlCacheEntry _WinINet_CreateUrlCacheGroup _WinINet_DeleteUrlCacheEntry _WinINet_DeleteUrlCacheGroup _WinINet_DetectAutoProxyUrl _WinINet_FindCloseUrlCache _WinINet_FindFirstUrlCacheEntry _WinINet_FindFirstUrlCacheEntryEx _WinINet_FindFirstUrlCacheGroup _WinINet_FindNextUrlCacheEntry _WinINet_FindNextUrlCacheEntryEx _WinINet_FindNextUrlCacheGroup _WinINet_FtpCommand _WinINet_FtpCreateDirectory _WinINet_FtpDeleteFile _WinINet_FtpFindFirstFile _WinINet_FtpGetCurrentDirectory _WinINet_FtpGetFile _WinINet_FtpGetFileSize _WinINet_FtpOpenFile _WinINet_FtpPutFile _WinINet_FtpRemoveDirectory _WinINet_FtpRenameFile _WinINet_FtpSetCurrentDirectory _WinINet_GetUrlCacheEntryInfo _WinINet_GetUrlCacheEntryInfoEx _WinINet_GetUrlCacheGroupAttribute _WinINet_GopherCreateLocator _WinINet_GopherFindFirstFile _WinINet_GopherGetAttribute _WinINet_GopherGetLocatorType _WinINet_GopherOpenFile _WinINet_HttpAddRequestHeaders _WinINet_HttpEndRequest _WinINet_HttpOpenRequest _WinINet_HttpQueryInfo _WinINet_HttpSendRequest _WinINet_HttpSendRequestEx _WinINet_InternetAttemptConnect _WinINet_InternetAutodial _WinINet_InternetAutodialHangup _WinINet_InternetCanonicalizeUrl _WinINet_InternetCheckConnection _WinINet_InternetClearAllPerSiteCookieDecisions _WinINet_InternetCloseHandle _WinINet_InternetCombineUrl _WinINet_InternetConfirmZoneCrossing _WinINet_InternetConnect _WinINet_InternetCrackUrl _WinINet_InternetCreateUrl _WinINet_InternetDial _WinINet_InternetEnumPerSiteCookieDecision _WinINet_InternetErrorDlg _WinINet_InternetFindNextFile _WinINet_InternetGetConnectedState _WinINet_InternetGetConnectedStateEx _WinINet_InternetGetCookie _WinINet_InternetGetCookieEx _WinINet_InternetGetLastResponseInfo _WinINet_InternetGetPerSiteCookieDecision _WinINet_InternetGoOnline _WinINet_InternetHangUp _WinINet_InternetLockRequestFile _WinINet_InternetOpen _WinINet_InternetOpenUrl _WinINet_InternetQueryDataAvailable _WinINet_InternetQueryOption _WinINet_InternetReadFile _WinINet_InternetReadFileEx _WinINet_InternetSetCookie _WinINet_InternetSetCookieEx _WinINet_InternetSetFilePointer _WinINet_InternetSetOption _WinINet_InternetSetPerSiteCookieDecision _WinINet_InternetSetStatusCallback _WinINet_InternetTimeFromSystemTime _WinINet_InternetTimeToSystemTime _WinINet_InternetUnlockRequestFile _WinINet_InternetWriteFile _WinINet_PrivacyGetZonePreferenceW _WinINet_PrivacySetZonePreferenceW _WinINet_ReadUrlCacheEntryStream _WinINet_ResumeSuspendedDownload _WinINet_RetrieveUrlCacheEntryFile _WinINet_RetrieveUrlCacheEntryStream _WinINet_SetUrlCacheEntryGroup _WinINet_SetUrlCacheEntryInfo _WinINet_SetUrlCacheGroupAttribute _WinINet_Shutdown _WinINet_Startup _WinINet_Struct_InternetCacheEntryInfo_ToArray _WinINet_Struct_InternetCacheGroupInfo_FromArray _WinINet_Struct_InternetCacheGroupInfo_ToArray _WinINet_Struct_UrlComponents_FromArray _WinINet_Struct_UrlComponents_ToArray _WinINet_UnlockUrlCacheEntryFile _WinINet_UnlockUrlCacheEntryStream NOT LIKELY TO BE IMPLEMENTED (don't seem to be relevant) ============================ _WinINet_CleanupCredentialCache _WinINet_CreateMD5SSOHash _WinINet_InternetDeInitializeAutoProxyDll _WinINet_InternetGetProxyInfo _WinINet_InternetInitializeAutoProxyDll


Remarks
There have been many UDFs released previously that rely on WinINet functions, but not many that are just direct wrappers around the functions (the FTP UDFs are the main ones that come to mind). The aim here is to get these functions into the standard UDFs, so that these UDFs can provide a base for other functions that rely on WinINet.

I've implemented most of the functions, but I haven't tested most of them either (the important ones, like InternetOpen/Connect and various HTTP functions are mainly what I tested).

Indeed, the constants file is still very disorganized (and incomplete), but I'll try getting around to that another time. In the meanwhile, I'm releasing what I currently have for wider testing and peer review of sorts. Feedback is welcome, as always :P

Anyhow, test away!

Edit: Just a note... before you use most of these functions, you'll need to call _WinINet_Startup().

Edit: And uh... I don't have example scripts for every single function at the moment. That would probably help with testing...

Edited by -Ultima-, 03 January 2010 - 02:44 AM.

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]







#2 WeMartiansAreFriendly

WeMartiansAreFriendly

    Where's the kaboom?

  • Active Members
  • PipPipPipPipPipPip
  • 1,245 posts

Posted 04 August 2008 - 06:41 PM

Really Nice job!

P.S. I'm surprised the scripts you submit don't get the attention they deserve.
Posted ImageDon't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

#3 -Ultima-

-Ultima-

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 267 posts

Posted 04 August 2008 - 10:34 PM

Hah, maybe it's because I work on boring things that most people don't care about? :P

Thanks for the compliment!
[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

#4 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 04 August 2008 - 10:52 PM

Hah, maybe it's because I work on boring things that most people don't care about? :P


Exactly as you said :-)
I don't understand this WinInet area very much but I believe mrRevoked if he said you did good job :-)
So keep up good job.

#5 -Ultima-

-Ultima-

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 267 posts

Posted 12 August 2008 - 02:09 AM

Finished implementing
_WinINet_FindCloseUrlCache _WinINet_FindFirstUrlCacheEntry _WinINet_FindFirstUrlCacheEntryEx _WinINet_FindFirstUrlCacheGroup _WinINet_FindNextUrlCacheEntry _WinINet_FindNextUrlCacheEntryEx _WinINet_FindNextUrlCacheGroup _WinINet_InternetCrackUrl _WinINet_InternetCreateUrl

That makes for a total of a whopping 91 functions (most of which probably won't ever be used, but they're there if needed... :P).

Edited by -Ultima-, 16 August 2008 - 01:25 PM.

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

#6 uteotw

uteotw

    Seeker

  • Active Members
  • 28 posts

Posted 21 August 2008 - 12:06 PM

Wonderful.
I actually needed the "cache" functions.


Update: I've just tried to use the "cache" functions and I'm not too sure what to do.

I get _WinINet_FindFirstUrlCacheGroup and _WinINet_GetUrlCacheGroupAttribute to work, but I'm not sure what to do with the result from _WinINet_GetUrlCacheGroupAttribute because what ever attribute I use it returns the same array.

#include <array.au3> #include <WinINet.au3> Opt("MustDeclareVars", 1) Opt("TrayIconDebug", 1) DllOpen("wininet.dll") Local $search = _WinINet_FindFirstUrlCacheGroup(0) ConsoleWrite(@error & @CRLF) _ArrayDisplay($search, "$search") Local $attribute = _WinINet_GetUrlCacheGroupAttribute($search[1], $CACHEGROUP_ATTRIBUTE_GROUPNAME) ConsoleWrite(@error & @CRLF) _ArrayDisplay($attribute, "$attribute")


FYI, I'm on WinXP64, don't think it should make a difference and there a files under my current user IE cache.

I guess I'll have to wait for some examples.

Edited by uteotw, 21 August 2008 - 11:33 PM.


#7 NELyon

NELyon

    Do you wanna brew my avatar?

  • Active Members
  • PipPipPipPipPipPip
  • 3,526 posts

Posted 21 August 2008 - 11:40 PM

Yippee. Just what I needed for a project of mine.

Thanks for the script ;)

#8 -Ultima-

-Ultima-

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 267 posts

Posted 22 August 2008 - 03:46 AM

@uteotw: Thanks, there is a bug with my implementation of the function (which I wholly expected). Here's an updated _WinINet_FindFirstUrlCacheEntry in the mean time which should stop the error from occurring:
AutoIt         
Func _WinINet_FindFirstUrlCacheEntry($iCacheEntryType = 0)     ; Set data/structures up     Local $sUrlSearchPattern = "*.*"     Switch $iCacheEntryType         Case 1             $sUrlSearchPattern = "cookie:"         Case 2             $sUrlSearchPattern = "visited:"     EndSwitch     Local $tCacheEntryInfoSize = DllStructCreate("dword")     ; (dummy call to get required structure size)     Local $avResult = DllCall("wininet.dll", _         "int", "FindFirstUrlCacheEntry" & $WIN32_FTYPE, _             $WIN32_TSTR, $sUrlSearchPattern, _             "ptr",       0, _             "ptr",       DllStructGetPtr($tCacheEntryInfoSize) _     )     ; (space slightly overallocated so we don't need to waste time creating the struct twice)     Local $tCacheEntryInfo = DllStructCreate($tagINTERNET_CACHE_ENTRY_INFO & "; byte[" & DllStructGetData($tCacheEntryInfoSize, 1) & "]")     ; Make DLL call     Local $avResult = DllCall("wininet.dll", _         "int", "FindFirstUrlCacheEntry" & $WIN32_FTYPE, _             $WIN32_TSTR, $sUrlSearchPattern, _             "ptr",       DllStructGetPtr($tCacheEntryInfo), _             "ptr",       DllStructGetPtr($tCacheEntryInfoSize) _     )     ; Return response     If @error Then Return SetError(1, 0, 0)     If Not $avResult[0] Then Return SetError(2, DllStructGetData($tCacheEntryInfoSize, 1), 0)     Local $avReturn[2] = [$avResult[0], $tCacheEntryInfo]     Return $avReturn EndFunc   ;==>_WinINet_FindFirstUrlCacheEntry


#include <array.au3> #include "WinINet.au3" Opt("MustDeclareVars", 1) Opt("TrayIconDebug", 1) DllOpen("wininet.dll") Local $search = _WinINet_FindFirstUrlCacheEntry() ConsoleWrite(_WinINet_DllStructReadArray(DllStructGetData($search[1], "LocalFileName"), 600)  & @CRLF)

Unfortunately, the other functions need updating, but I won't be able to get to them until at least tomorrow.
[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

#9 uteotw

uteotw

    Seeker

  • Active Members
  • 28 posts

Posted 22 August 2008 - 04:42 PM

_WinINet_DllStructReadArray(), I could I have missed it!!? I must have been blind when reading the list of functions.

Thanks for the _WinINet_FindFirstUrlCacheEntry() update and no rush for the rest.

#10 -Ultima-

-Ultima-

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 267 posts

Posted 22 August 2008 - 07:56 PM

It should hopefully be fixed now (new attachment uploaded). You'll no longer need to worry about the INTERNET_CACHE_ENTRY_INFO structures, as the information is now extracted into an easier-to-use array. There are examples on how to use the two functions included as well.

And yeah, you shouldn't really need to know about _WinINet_DllStructReadArray(), as it's supposed to be an internal function.

Edit: I forgot to make an example for _WinINet_GetUrlCacheGroupAttribute()... Well, anyway, it currently returns a struct (not an array) that you can read using DllStructGetData(). You can figure out the members of the structure by looking at the definition for $tagINTERNET_CACHE_GROUP_INFO in WinINetConstants.au3. That it's currently using a struct is subject to possible change for the future, so keep an eye on the changelog ;)

Edited by -Ultima-, 22 August 2008 - 10:25 PM.

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

#11 HeidiR

HeidiR

    Adventurer

  • Active Members
  • PipPip
  • 102 posts

Posted 26 August 2008 - 07:00 PM

Ultima,

Looks like a very good effort! I just started a small test project to try and put a file to my server. Unfortunately, I can't get passed the connect function. Always returns zero. Is there a simple example somewhere? My code is below:

CODE
Local $hdl = _WinINet_InternetOpen('')

if @error then
msgbox(0,"Error","Open Error " & $hdl)
exit
Endif

$hdl = _WinINet_InternetConnect($hdl, 1, $server, 21, 0, $uid, $pw )

if @error then
msgbox(0,"Error","Connect Error " & $hdl)
exit
Endif

HeidiRFind free applications, code examples and more on my site at:http://heidisdownloads.com/

#12 -Ultima-

-Ultima-

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 267 posts

Posted 26 August 2008 - 07:37 PM

You need to call DllOpen("wininet.dll") before using any of the functions (as noted in the first post) because otherwise, AutoIt opens/closes wininet.dll every time you call a function. When the DLL is closed, any pointers/handles returned while the DLL was opened become invalid, and can't be expected to work when you reopen the DLL again (in another function).

I think I'll go with the _WinINet_Startup()/_WinINet_Shutdown() route next update...

Edited by -Ultima-, 26 August 2008 - 07:44 PM.

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

#13 HeidiR

HeidiR

    Adventurer

  • Active Members
  • PipPip
  • 102 posts

Posted 26 August 2008 - 08:38 PM

Thanks Ultma. DllOpen("wininet.dll") got me past the connect issue. Next challenge is why put is failing. Still researching.
HeidiRFind free applications, code examples and more on my site at:http://heidisdownloads.com/

#14 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 26 August 2008 - 09:41 PM

Great work ultima !!!
This looks like very good base for high level FTP UDF.

#15 -Ultima-

-Ultima-

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 267 posts

Posted 27 August 2008 - 03:38 AM

As well as high-level HTTP(S) functions ;) Then there's always Gopher+, but it's a completely foreign protocol to me xD

Anyhow, thanks for the compliments!
[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

#16 Xenobiologist

Xenobiologist

    Xx Code~Mega xX

  • MVPs
  • 4,729 posts

Posted 27 August 2008 - 07:33 AM

Hi,

looks really nice, but I guess creating some little examples what are the advantages would raise the interest of the ftp.au3 users.

Mega
Scripts & functions Organize Includes Let Scite organize the include files *newYahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication)_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

#17 HeidiR

HeidiR

    Adventurer

  • Active Members
  • PipPip
  • 102 posts

Posted 27 August 2008 - 01:46 PM

Ultima,

Thanks for your help. I am in the process of creating some examples using your WinINet.au3 UDF. I have been successful in using the following functions:
_WinINet_InternetOpen
_WinINet_InternetConnect
_WinINet_FtpPutFile
_WinINet_FtpGetFile
_WinINet_FtpCreateDirectory

I am currently working on _WinINet_FtpFindFirstFile but having difficulity getting data out of the returned structure. In the code below, the message box displays 2 for @error and 0 for fname. What am I missing???



CODE
Local $ftp_ar = _WinINet_FtpFindFirstFile($hdl3, '/www/*.*')

if @error then
msgbox(0,"Error","Read Directory Error " & $ftp_ar[0])
exit
Endif

Local $hdl4 = $ftp_ar[0]
Local $struct = $ftp_ar[1]

Local $fname = DllStructGetData($struct,"cFileName")

msgbox(0, @error, $fname)

HeidiRFind free applications, code examples and more on my site at:http://heidisdownloads.com/

#18 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 27 August 2008 - 03:04 PM

I am currently working on _WinINet_FtpFindFirstFile but having difficulity getting data out of the returned structure. In the code below, the message box displays 2 for @error and 0 for fname. What am I missing???

CODE
Local $ftp_ar = _WinINet_FtpFindFirstFile($hdl3, '/www/*.*')

if @error then
msgbox(0,"Error","Read Directory Error " & $ftp_ar[0])
exit
Endif

Local $hdl4 = $ftp_ar[0]
Local $struct = $ftp_ar[1]

Local $fname = DllStructGetData($struct,"cFileName")

msgbox(0, @error, $fname)

As far as I know you must use ABSOLUTE path:

Local $ftp_ar = _WinINet_FtpFindFirstFile($hdl3, 'ftp://ftp.somewhere.com/www/*.*')

I use FTP UDF and I use _FtpFileFindFirst() this way.

Edited by Zedna, 27 August 2008 - 03:06 PM.


#19 HeidiR

HeidiR

    Adventurer

  • Active Members
  • PipPip
  • 102 posts

Posted 27 August 2008 - 03:49 PM

As far as I know you must use ABSOLUTE path:

Local $ftp_ar = _WinINet_FtpFindFirstFile($hdl3, 'ftp://ftp.somewhere.com/www/*.*')


I use FTP UDF and I use _FtpFileFindFirst() this way.

Zedna,

Thanks for the information. Funny thing. When I use the absolute path ('ftp://ftp.somewhere.com/www/*.*') I receive my "Read Directory Error" msgbox error after the call, which is trapped by @error. However, when I use my original '/www/*.*' path in the call, I don't get an error after the call. Just can't figure out how to get the file info out of the structure!!!
HeidiRFind free applications, code examples and more on my site at:http://heidisdownloads.com/

#20 HeidiR

HeidiR

    Adventurer

  • Active Members
  • PipPip
  • 102 posts

Posted 27 August 2008 - 06:30 PM

Ultima,

I think there may be a bug in the _WinINet_InternetFindNextFile code. The current code below sets @error to 0 on an error and returns true as if it succeeded.

; Return response
If @error Or Not $avResult[0] Then SetError(1, 0, 0)
Return True

Maybe the code should look like:

; Return response
If @error Or Not $avResult[0] Then
SetError(1, 0, 0)
Return False
Else
Return True
Endif


Note that _WinINet_FtpFindFirstFile has the same issue.

Thanks.
HeidiRFind free applications, code examples and more on my site at:http://heidisdownloads.com/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users