CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: Problem with establishing FTP using InternetConnect

  1. #1
    Join Date
    Aug 2008

    Problem with establishing FTP using InternetConnect


    I am having a problem using the InternetConnect API to establish an FTP connection. using getlasterror returns error 87 which is invalid parameter.
    I am not sure which parameter is invalid. I do believe the internet handle i am passing it is valid. heres the code

    m_hConnHandle = InternetConnect(m_hInetHandle, "", 0, "", "", 1, 0, 0)

    Dim i As Int32 = Err.LastDllError()

    i is always = 87

    I tried passing in 21 for the port but that does not help
    any help would be appreciated.

  2. #2
    Join Date
    Jul 2001
    Sunny South Africa

    Re: Problem with establishing FTP using InternetConnect

    Welcome to the forums!

    You're in luck As I've been doing a lot with FTP these days.

    I've done this :
     ' API declarations
        <DllImport("wininet.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
        Public Function InternetConnect(ByVal hInternet As IntPtr, ByVal lpszServerName As String, ByVal nServerPort As Short, ByVal lpszUserName As String, ByVal lpszPassword As String, ByVal dwService As Integer, _
        ByVal dwFlags As Integer, ByRef dwContext As Integer) As IntPtr
        End Function
        <DllImport("wininet.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
        Public Function InternetOpen(ByVal lpszAgent As String, ByVal dwAcessType As Integer, ByVal lpszProxyName As String, ByVal lpszProxyBypass As String, ByVal dwFlags As Integer) As IntPtr
        End Function
    'API Constants
        Public Const INTERNET_OPEN_TYPE_DIRECT = 1                         ' direct to net
        Public Const INTERNET_DEFAULT_FTP_PORT = 21                ' default for FTP servers
        Public Const INTERNET_SERVICE_FTP = 1
    'In My frmLoad:
            Dim hInternet As IntPtr = InternetOpen(Nothing, INTERNET_OPEN_TYPE_DIRECT, Nothing, Nothing, 0)
            Dim hConnection As IntPtr = InternetConnect(hInternet, rServer, INTERNET_DEFAULT_FTP_PORT, rUser, rPass, INTERNET_SERVICE_FTP, 0, 0)
    And it works fine for me, try it as well.
    All my Articles

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)