Jump to content

Recommended Posts

Posted (edited)

Heres a small function and example for setting up InternetStatusCallback. You need the new Beta to run the example. Hope someone can use it.

Function:

;FUNCTION# ====================================================================================================================
; Name...........: _InternetSetStatusCallback
; Description ...: Registers callback function that WinINet functions can call as progress is made during an operation.
; Syntax.........: _InternetSetStatusCallback($l_InternetSession, $sFunctionName)
; Parameters ....: $l_InternetSession   - as returned by _FTP_Open().
;                  $sFunctionName       - Function Name
; Return values .: Success      - array containing the following information:
;                               $array[0] = Handle to DllCallBackRegister() to be used with DllCallBackFree($array[0]).
;                               $array[1] = Handle to CallBack Function
; Author ........: bchris01
; Link ..........: @@MsdnLink@@ InternetSetStatusCallback
; Example .......: Yes
; ===============================================================================================================================
Func _InternetSetStatusCallback($l_InternetSession, $sFunctionName)
    Local $CallBackRegister, $CallBackFunction, $Pointer_To_CallBack_Function
    $CallBackRegister = DllCallbackRegister($sFunctionName, "none", "ptr;ptr;dword;ptr;dword")
    $Pointer_To_CallBack_Function = DllCallbackGetPtr($CallBackRegister)
    $CallBackFunction = DllCall('wininet.dll', "ptr", "InternetSetStatusCallback", "ptr", $l_InternetSession, "ulong_ptr", $Pointer_To_CallBack_Function)
    $CallBackFunction[0] = $CallBackRegister
    Return $CallBackFunction
EndFunc   ;==>_InternetSetStatusCallback

Example:

#include <FTPEx.au3>

Global $server = 'gatekeeper.dec.com', $username = '', $pass = ''
$Open = _FTP_Open('MyFTP Control')
$InternetStatusCallback = _InternetSetStatusCallback($Open, '_InternetStatusCallback')
$Conn = _FTP_Connect($Open, $server, $username, $pass, 0, 0, 1, 0, $InternetStatusCallback[1])
_FTP_DirSetCurrent($Conn, '/pub')
_FTP_FileGet($Conn, '/pub/tom/snooker-test-1-_0001.JPG', @ScriptDir & '\snooker-test-1-_0001.JPG', False, 0, 0, $InternetStatusCallback[1])
$Ftpc = _FTP_Close($Open)
DllCallbackFree($InternetStatusCallback[0])


Func _InternetStatusCallback($hInternet, $dwContent, $dwInternetStatus, $lpvStatusInformation, $dwStatusInformationLength)

    Switch $dwInternetStatus
        Case 50; $INTERNET_STATUS_CLOSING_CONNECTION
            ConsoleWrite('CLOSING_CONNECTION.....'& @CRLF)

        Case 51; $INTERNET_STATUS_CONNECTION_CLOSED
            ConsoleWrite('CONNECTION_CLOSED' & @CRLF)

        Case 20; $INTERNET_STATUS_CONNECTING_TO_SERVER
            ConsoleWrite('CONNECTING_TO_SERVER.....'& @CRLF)

        Case 21; $INTERNET_STATUS_CONNECTED_TO_SERVER
            ConsoleWrite('CONNECTED_TO_SERVER' & @CRLF)

        Case 42; $INTERNET_STATUS_CTL_RESPONSE_RECEIVED
            ConsoleWrite('CTL_RESPONSE_RECEIVED' & @CRLF)

        Case 120; $INTERNET_STATUS_INTERMEDIATE_RESPONSE
            ConsoleWrite('INTERMEDIATE_RESPONSE' & @CRLF)

        Case 43; $INTERNET_STATUS_PREFETCH
            ConsoleWrite('PREFETCH' & @CRLF)

        Case 110;$INTERNET_STATUS_REDIRECT
            ConsoleWrite('REDIRECT' & @CRLF)

        Case 100; $INTERNET_STATUS_REQUEST_COMPLETE
            ConsoleWrite('REQUEST_COMPLETE' & @CRLF)

        Case 60 ;$INTERNET_STATUS_HANDLE_CREATED
            ConsoleWrite('HANDLE_CREATED ' & @CRLF)

        Case 70 ;$INTERNET_STATUS_HANDLE_CLOSING
            ConsoleWrite('HANDLE_CLOSING' & @CRLF)

        Case 30; $INTERNET_STATUS_SENDING_REQUEST
            ConsoleWrite('SENDING_REQUEST.....')

        Case 31; $INTERNET_STATUS_REQUEST_SENT
            Local $Size, $iBytesRead
            $Size = DllStructCreate('dword')
            _WinAPI_ReadProcessMemory(_WinAPI_GetCurrentProcess(), $lpvStatusInformation, DllStructGetPtr($Size), $dwStatusInformationLength, $iBytesRead)
            ConsoleWrite('REQUEST_SENT | Size = ' & DllStructGetData($Size, 1) & ' Bytes    Bytes read = ' & $iBytesRead  & @CRLF)
            $Size = 0
        Case 40; $INTERNET_STATUS_RECEIVING_RESPONSE
            ConsoleWrite('RECEIVING_RESPONSE.....'& @CRLF)

        Case 41;$INTERNET_STATUS_RESPONSE_RECEIVED
            Local $Size, $iBytesRead
            $Size = DllStructCreate('dword')
            _WinAPI_ReadProcessMemory(_WinAPI_GetCurrentProcess(), $lpvStatusInformation, DllStructGetPtr($Size), $dwStatusInformationLength, $iBytesRead)
            ConsoleWrite('REQUEST_SENT | Size = ' & DllStructGetData($Size, 1) & ' Bytes    Bytes read = ' & $iBytesRead  & @CRLF)
            $Size = 0
        Case 200; $INTERNET_STATUS_STATE_CHANGE
            ConsoleWrite('STATE_CHANGE' & @CRLF)

        Case 10; $INTERNET_STATUS_RESOLVING_NAME
            ConsoleWrite('RESOLVING_NAME.....'& @CRLF)

        Case 11; $INTERNET_STATUS_NAME_RESOLVED
            ConsoleWrite('NAME_RESOLVED' & @CRLF)

        Case Else
            ConsoleWrite($dwInternetStatus & @CRLF)

    EndSwitch

EndFunc   ;==>_InternetStatusCallback

Func _InternetSetStatusCallback($l_InternetSession, $sFunctionName)
    Local $CallBackRegister, $CallBackFunction, $Pointer_To_CallBack_Function
    $CallBackRegister = DllCallbackRegister($sFunctionName, "none", "ptr;ptr;dword;ptr;dword")
    $Pointer_To_CallBack_Function = DllCallbackGetPtr($CallBackRegister)
    $CallBackFunction = DllCall('wininet.dll', "ptr", "InternetSetStatusCallback", "ptr", $l_InternetSession, "ulong_ptr", $Pointer_To_CallBack_Function)
    $CallBackFunction[0] = $CallBackRegister
    Return $CallBackFunction
EndFunc   ;==>_InternetSetStatusCallback

Edit: Changed function to return an array that includes a handle to Dllcallbackregister().

Edited by Beege
Posted

this is perfect thanks, does it work with tcpconnect() sessions too?

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")
For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)
Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI"
Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;
MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)
Posted

Thanks. Glad it could help someone. And no it will not work with tcpconnect() or any of Autoit's built in functions. I should only work with wininet.dll functions that allow you to specify a callback function. Here is a list of the commands from FTPEx.au3 that you can use it with.

_FTP_Command()

_FTP_Connect()

_FTP_FileGet

_FTP_FileOpen()

_FTP_FilePut()

_FTP_FindFileFirst()

It could also work with dll function InternetOpenUrl used in _INetGetSource().

  • 2 months later...
Posted

Unfortunately I do not saw this thread earlier. Good approach, but there is one question. How to get the number of downloaded bytes for a file in percentage. A simple calculation gives a difference of 32 bytes. This is a constant?

  • 8 months later...
Posted

Hi All

I Am not able to download files from FTP using _FTP_Fileget() function, everytime i get return value as 0

i am able to upload files to FTP using _FTP_DirPutContents() function

please advice me how to proceed

this is very very urgent

please anybody reply

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...