473,507 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Jan 9 '06 #1
2 3125
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
Jan 10 '06 #2
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.

Jan 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7114
by: scott ocamb | last post by:
hello I have implemented a solution using async methods. There is one async method that can be invoked multiple times, ie there are multiple async "threads" running at a time. When these...
0
2155
by: Boltar | last post by:
Hello, I am trying to use a CustomValidator control to perform client-side validation via a server callback. I have an example below that validates if a textbox contains an odd number. I...
0
1782
by: Robert | last post by:
After failing on a yield/iterator-continuation problem in Python (see below) I tried the Ruby (1.8.2) language first time on that construct: The example tries to convert a block callback interface...
3
3038
by: ryan.mitchley | last post by:
Hi all I have a class (cPort) that is designed to receive objects and, depending on the type, call a handler (callback) in any descendant of a cProcessBlock class. Callback functions take a...
4
5864
by: Jimmy | last post by:
I need to use Asynchronous Socket functions in a server application and am learning from sources such as the MSDN2 (http://msdn2.microsoft.com/en-us/library/bbx2eya8.aspx). What I observed is that...
0
1177
by: Brian | last post by:
Hi, I've been trying to get a simple client / script callback to work. I was using IE6 to the ASP Development Server / IIS 5 and it just didn't work. I ended up using an example straight from an...
6
7646
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in...
10
6924
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
0
2091
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via...
5
4289
by: Jef Driesen | last post by:
I have a C DLL that I want to use from a C# project. The C header file contains these declarations: typedef void (*callback_t) (const unsigned char *data, unsigned int size, void *userdata);...
0
7110
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.