Jump to content

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


-Ultima-
 Share

Recommended Posts

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

WinINet_2010_01_02.zip

- Minor tweaks

WinINet_2008_09_13.zip

- 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)

WinINet_2008_08_22.zip

- 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()

WinINet_2008_08_16.zip

- Fixed some string/buffer length issues

WinINet_2008_08_11.zip

- 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

WinINet.zip

- Initial release

Function List

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-

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

Link to comment
Share on other sites

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-

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

Link to comment
Share on other sites

  • 2 weeks later...

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
Link to comment
Share on other sites

@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:

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() ]

Link to comment
Share on other sites

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-

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

Link to comment
Share on other sites

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/
Link to comment
Share on other sites

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-

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

Link to comment
Share on other sites

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/
Link to comment
Share on other sites

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

Yahtzee 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

Link to comment
Share on other sites

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/
Link to comment
Share on other sites

HeidiR said:

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 Melba23
Link to comment
Share on other sites

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/
Link to comment
Share on other sites

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/
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...