473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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 3118
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
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
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
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
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
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
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
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
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
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
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.