VB.NET • Import FTP Methods

Listing 2. Transferring files with FTP is much simpler because the Windows WININET.dll does most of the work for you. This class imports the necessary FTP methods you'll need to accomplish the task.

Public Class FTP
<DllImport("WININET.DLL", _
	EntryPoint:="InternetCloseHandle")> _
	Public Shared Function CloseConnection(ByVal _
	HINet As Integer) As Integer
End Function
<DllImport("WININET.DLL", _
	EntryPoint:="InternetOpenA")> _
	Public Shared Function Open(ByVal _
	sAgent As String, ByVal lAccessType _
	As Integer, ByVal sProxyName As String, _
	ByVal sProxyBypass As String, _
	ByVal lFlags As Integer) As Integer
End Function
<DllImport("WININET.DLL", _
	EntryPoint:="InternetConnectA")> _
	Public Shared Function Connect( _
	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
<DllImport("WININET.DLL", _
	EntryPoint:="FtpPutFileA")> _
	Public Shared Function PutFile( _
	ByVal hFtpSession As Integer, _
	ByVal lpszLocalFile As String, _
	ByVal lpszRemoteFile As String, _
	ByVal dwFlags As Integer, _
	ByVal dwContext As Integer) As Boolean
End Function
<DllImport("WININET.DLL", _
	EntryPoint:="FtpGetFileA")> _
	Public Shared Function GetFile( _
	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
End Class