|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ftp callback example C#Hello all,
I've looked all over the internet and am not having much luck. I'm trying to implement a callback out of a ftpgetfile method so I can give my users an indication of the progress of their download since the files are pretty big. I'm having problems setting up the callback using the InternetSetStatusCallback method. I found a VB6 version, but having all kinds of problems converting it to C#. I'm new to C#, so I'm not all that familiar with event handlers, but I don't understand how to use InternetSetStatusCallback or what it passes to the callback method. Does anyone have an example of this in C# or vb.net ? Any help would be most appreciated. Thanks, Mark Hello Mark,
Take a look at this: ~ #Region "Declarations" Friend Declare Function InternetSetStatusCallback Lib "wininet.dll" ( _ ByVal hInternet As IntPtr, _ ByVal lpfnInternetCallback As INTERNET_STATUS_CALLBACK _ ) As Integer Friend Delegate Sub INTERNET_STATUS_CALLBACK( _ ByVal hInternet As IntPtr, _ ByRef dwContext As Integer, _ ByVal dwInternetStatus As InternetStatus, _ ByRef lpvStatusInformation As InternetState, _ ByVal dwStatusInformationLength As Integer _ ) Friend Enum InternetStatus ResolvingName = 10 NameResolved = 11 ConnectingToServer = 20 ConnectedToServer = 21 SendingRequest = 30 RequestSent = 31 ReceivingResponse = 40 ResponseReceived = 41 CtlResponseReceived = 42 Prefetch = 43 ClosingConnection = 50 ConnectionClosed = 51 HandleCreated = 60 HandleClosing = 70 RequestComplete = 100 Redirect = 110 IntermediateResponse = 120 StateChange = 200 End Enum Friend Enum InternetState Connected = &H1 Disconnected = &H2 DisconnectedByUser = &H10 Idle = &H100 Busy = &H200 End Enum #End Region Protected Overrides Sub OnClick(ByVal e As System.EventArgs) MyBase.OnClick(e) InternetSetStatusCallback(hInternet, AddressOf InternetSetStatusCallback) End Sub Friend Sub InternetStatusCallback( _ ByVal hInternet As IntPtr, _ ByRef dwContext As Integer, _ ByVal dwInternetStatus As InternetStatus, _ ByRef lpvStatusInformation As InternetState, _ ByVal dwStatusInformationLength As Integer _ ) REM Handle callback End Sub ~ It wasn't tested but should work. Hope it will, Roman Thanks for the reply. I'll give it a try.
Temporarily, what I did was change to code to not use a FTPGetFile, but InternetReadFile instead since I have control over the buffer size. My preference was to use FTPGetFile, so I'll give this is a shot. Thanks again. |
|||||||||||||||||||||||