Private Declare Function InternetOpen _
Lib "wininet.dll" Alias "InternetOpenA" ( _
ByVal sAgent As String, _
ByVal nAccessType As Long, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal nFlags As Long _
) As Long
Private Declare Function InternetConnect _
Lib "wininet.dll" Alias "InternetConnectA" ( _
ByVal hInternetSession As Long, _
ByVal sServerName As String, _
ByVal nServerPort As Integer, _
ByVal sUserName As String, _
ByVal sPassWord As String, _
ByVal nService As Long, _
ByVal nFlags As Long, _
ByVal nContext As Long _
) As Long
Private Declare Function FtpPutFile _
Lib "wininet.dll" Alias "FtpPutFileA" ( _
ByVal hFtpSession As Long, _
ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Long, _
ByVal dwContext As Long _
) As Boolean
Private Declare Function InternetCloseHandle Lib "wininet.dll" ( _
ByVal hInet As Long _
) As Integer
Public Enum eTransferType
FTP_TRANSFER_TYPE_ASCII = &H1
FTP_TRANSFER_TYPE_BINARY = &H2
End Enum
Private Const INTERNET_FLAG_EXISTING_CONNECT As Long = &H20000000
Private Const INTERNET_FLAG_PASSIVE As Long = &H8000000
Private Const INTERNET_SERVICE_FTP = 1
Private Const INTERNET_OPEN_TYPE_PRECONFIG As Long = 0
Private hSession As Long
Private hINetSession As Long
Public Function Connect( _
ByVal sRemoteHost As String, _
ByVal sUserName As String, _
ByVal sPwd As String, _
Optional ByVal nPort As Long = 21) As Boolean
If (hSession + hINetSession) <> 0 Then
CloseConnection
End If
hINetSession = InternetOpen("MyApplication", _
INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, vbNullString, 0)
If hINetSession Then
hSession = InternetConnect(hINetSession, sRemoteHost, _
nPort, sUserName, sPwd, INTERNET_SERVICE_FTP, _
INTERNET_FLAG_EXISTING_CONNECT, 0)
End If
Connect = (hSession <> 0)
End Function
Public Sub CloseConnection()
If hSession Then
Call InternetCloseHandle(hSession)
End If
If hINetSession Then
Call InternetCloseHandle(hINetSession)
End If
hSession = 0
hINetSession = 0
End Sub
Public Function UploadFile( _
ByVal sLocalFile As String, _
sRemoteFile As String, _
enTransferType As eTransferType) As Boolean
If hSession Then
UploadFile = FtpPutFile(hSession, sLocalFile, sRemoteFile, enTransferType, 0)
End If
End Function