Imports System
Imports System.Runtime.InteropServices
Public Class DllImports
<DllImport("WinInet.dll", _
EntryPoint:="InternetOpen", _
CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function InternetOpen( _
ByVal lpszAgent As String, _
ByVal dwAccessType As Int32, _
ByVal lpszProxyName As String, _
ByVal lpszProxyBypass As String, _
ByVal dwFlags As Int32) As IntPtr
End Function
<DllImport("WinInet.dll", _
EntryPoint:="InternetConnect", _
CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function InternetConnect( _
ByVal hInternet As IntPtr, _
ByVal lpszServerName As String, _
ByVal nServerPort As Int32, _
ByVal lpszUsername As String, _
ByVal lpszPassword As String, _
ByVal dwService As Int32, _
ByVal dwFlags As Int32, _
ByVal dwContext As IntPtr) As IntPtr
End Function
<DllImport("WinInet.dll", _
EntryPoint:="InternetCloseHandle", _
CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function InternetCloseHandle( _
ByVal hInternet As IntPtr) As Int32
End Function
<DllImport("WinInet.dll", _
EntryPoint:="InternetGetLastResponseInfo", _
CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function InternetGetLastResponseInfo( _
ByRef lpdwError As Int32, _
ByVal lpszBuffer As System.Text.StringBuilder, _
ByRef lpdwBufferLength As Int32) As Int32
End Function
Public Shared Function CheckFtpLogin( _
ByVal FtpServerName As String, _
ByVal FtpUsername As String, _
ByVal FtpPassword As String) As Boolean
Dim InternetOpen, InternetConnect As IntPtr
Dim a As Int32 = 724 'whatever
Dim p As New IntPtr(a)
InternetOpen = DllImports.InternetOpen( _
"Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2;+.NET+CLR+1.1.4322)", _
0, _
Nothing, _
Nothing, _
0)
If IntPtr.op_Equality(InternetOpen, IntPtr.Zero) Then
'InternetOpen failed.
'Call Marshal.GetLastWin32Error() for the errorcode
Return False
End If
InternetConnect = DllImports.InternetConnect( _
InternetOpen, _
FtpServerName, _
21, _
FtpUsername, _
FtpPassword, _
1, _
&H8000000, _
p)
If IntPtr.op_Equality(InternetConnect, IntPtr.Zero) Then
'InternetOpen failed.
'Call Marshal.GetLastWin32Error() for the errorcode
'Call InternetGetLastResponseInfo to see the response
Dim lpdwError As Int32 = 0
Dim lpdwBufferLength As Int32 = 2048
Dim lpszBuffer As _
New System.Text.StringBuilder(lpdwBufferLength)
DllImports.InternetGetLastResponseInfo( _
lpdwError, lpszBuffer, lpdwBufferLength)
'Free the handle:
DllImports.InternetCloseHandle(InternetOpen)
Return False
End If
' Everything OK
'Free the handles:
DllImports.InternetCloseHandle(InternetOpen)
DllImports.InternetCloseHandle(InternetConnect)
Return True
End Function
End Class