ftp callback example C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • marfi95@yahoo.com

    #1

    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 InternetSetStat usCallback 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 InternetSetStat usCallback 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

  • Dragon

    #2
    Re: ftp callback example C#

    Hello Mark,

    Take a look at this:

    ~
    #Region "Declaratio ns"
    Friend Declare Function InternetSetStat usCallback Lib "wininet.dl l"
    ( _
    ByVal hInternet As IntPtr, _
    ByVal lpfnInternetCal lback As INTERNET_STATUS _CALLBACK _
    ) As Integer


    Friend Delegate Sub INTERNET_STATUS _CALLBACK( _
    ByVal hInternet As IntPtr, _
    ByRef dwContext As Integer, _
    ByVal dwInternetStatu s As InternetStatus, _
    ByRef lpvStatusInform ation As InternetState, _
    ByVal dwStatusInforma tionLength As Integer _
    )

    Friend Enum InternetStatus
    ResolvingName = 10
    NameResolved = 11
    ConnectingToSer ver = 20
    ConnectedToServ er = 21
    SendingRequest = 30
    RequestSent = 31
    ReceivingRespon se = 40
    ResponseReceive d = 41
    CtlResponseRece ived = 42
    Prefetch = 43
    ClosingConnecti on = 50
    ConnectionClose d = 51
    HandleCreated = 60
    HandleClosing = 70
    RequestComplete = 100
    Redirect = 110
    IntermediateRes ponse = 120
    StateChange = 200
    End Enum

    Friend Enum InternetState
    Connected = &H1
    Disconnected = &H2
    DisconnectedByU ser = &H10
    Idle = &H100
    Busy = &H200
    End Enum
    #End Region
    Protected Overrides Sub OnClick(ByVal e As System.EventArg s)
    MyBase.OnClick( e)
    InternetSetStat usCallback(hInt ernet, AddressOf
    InternetSetStat usCallback)
    End Sub

    Friend Sub InternetStatusC allback( _
    ByVal hInternet As IntPtr, _
    ByRef dwContext As Integer, _
    ByVal dwInternetStatu s As InternetStatus, _
    ByRef lpvStatusInform ation As InternetState, _
    ByVal dwStatusInforma tionLength As Integer _
    )
    REM Handle callback
    End Sub
    ~

    It wasn't tested but should work.
    Hope it will,
    Roman


    Comment

    • marfi95@yahoo.com

      #3
      Re: ftp callback example C#

      Thanks for the reply. I'll give it a try.

      Temporarily, what I did was change to code to not use a FTPGetFile, but
      InternetReadFil e 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.

      Comment

      Working...