Calling WinINet API from VB.NET

Description

This is an API which connects with the remote server . Inputs are the user name and password which are needed to connect with the server. For demonstration purpose an API called "FtpGetFile" is illustrated. Other API's for deleting, putting , renaming and moving can be tried out. Please contact the author for any problems.

Source Code

API Description

  1. PublicShared Function <DllImport("wininet.dll")> _
    InternetOpen(ByVal sAgentAs String, _
    ByVal lAccessTypeAs Long, _
    ByVal sProxyNameAs String, _
    ByVal sProxyBypassAs String, _
    ByVal lFlagsAs Integer) AsInteger
    End
    Function

    InternetOpen is the first Win32 Internet function called by an application. It tells the Internet DLL to initialize internal data structures and prepare for future calls from the application.
  2. PublicShared Function <DllImport("wininet.dll")> _
    InternetConnect(ByVal hInternetSessionAs Integer, _
    ByVal sServerNameAs String, _
    ByVal nServerPortAs Integer, _
    ByVal sUsernameAs String, _
    ByVal sPasswordAs String, _
    ByVal lServiceAs Integer, _
    ByVal lFlagsAs Integer, _
    ByVal lContextAs Integer) AsInteger
    End
    Function

    This function opens an FTP or HTTP session for a specified site.
  3. PublicShared Function <DllImport("wininet.dll")> _
    FtpGetFile(ByVal hFtpSessionAs Integer, _
    ByVal lpszRemoteFileAs String, _
    ByVal lpszNewFileAs String, _
    ByVal fFailIfExistsAs Boolean, _
    ByVal dwFlagsAndAttributesAs Integer, _
    ByVal dwFlagsAs Integer, _
    ByVal dwContextAs Integer) AsBoolean
    End
    Function

    This function retrieves a file from the FTP server and stores it under the specified file name, creating a new local file in the process. 

General Description

Before running the code make sure you enter a correct site name, user name and password, which will connect, to the site. On having proper user access you can download, rename, delete and move the files using API's. This code is written where the access is limited to the users. Please find my other API which will download a file from remote server with no "Save to disk" dialog box.