ARTICLE

Calling WinINet API from VB.NET

Posted by Vishal Kulkarni Articles | Visual Basic 2010 May 15, 2004
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.
Download Files:
 
Reader Level:

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. Public Shared Function <DllImport("wininet.dll")> _
    InternetOpen(
    ByVal sAgent As String, _
    ByVal lAccessType As Long, _
    ByVal sProxyName As String, _
    ByVal sProxyBypass As String, _
    ByVal lFlags As Integer) As Integer
    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. Public Shared Function <DllImport("wininet.dll")> _
    InternetConnect(
    ByVal hInternetSession As Integer, _
    ByVal sServerName As String, _
    ByVal nServerPort As Integer, _
    ByVal sUsername As String, _
    ByVal sPassword As String, _
    ByVal lService As Integer, _
    ByVal lFlags As Integer, _
    ByVal lContext As Integer) As Integer
    End
    Function

    This function opens an FTP or HTTP session for a specified site.

  3. Public Shared Function <DllImport("wininet.dll")> _
    FtpGetFile(
    ByVal hFtpSession As Integer, _
    ByVal lpszRemoteFile As String, _
    ByVal lpszNewFile As String, _
    ByVal fFailIfExists As Boolean, _
    ByVal dwFlagsAndAttributes As Integer, _
    ByVal dwFlags As Integer, _
    ByVal dwContext As Integer) As Boolean
    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.

Login to add your contents and source code to this article
share this article :
post comment
 

How to interop with InternetStatusCallback/InternetSetStatusCallback

Posted by Raul Contreras Oct 23, 2010

Those files are part of the .NET framework......

Posted by Orlando Salcido Nov 17, 2007

The following is a list of references that are missing in your project zip:

Microsoft.Win32.Interop

System.Configuration

System.Diagnostics

System.WinForms

System.WinForms.Design

System.XML.Serialization

Any chance you could select the "Copy Locally" option for these references to true and compile the project that way (and maybe update the zip file to contain those dlls?

 

 

 

 

Posted by DigiOz Multimedia Apr 07, 2006
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor