ARTICLE
Calling WinINet API from VB.NET
Tags: .NET, API, Dialog Box, DllImport, FTP, FTP Server, FtpGetFile, HTTP, Language, VB.NET, Win32, WinINet API in VB.NET., WinINetAPI
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:
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 :
-
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. -
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.
-
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.