Beege Posted August 8, 2009 Posted August 8, 2009 (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: expandcollapse popup#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 October 13, 2009 by Beege Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator
JRSmile Posted August 9, 2009 Posted August 9, 2009 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:-)
Beege Posted August 9, 2009 Author Posted August 9, 2009 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(). Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator
Yashied Posted October 29, 2009 Posted October 29, 2009 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? 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...
NewTester Posted July 20, 2010 Posted July 20, 2010 Hi AllI 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() functionplease advice me how to proceedthis is very very urgentplease anybody reply
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